Jump to content


Photo

Need help with adding some code to working page


  • Please log in to reply
2 replies to this topic

#1 tsiedsma

tsiedsma
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 09 March 2006 - 08:06 PM

This code will take in three variables ($address, $city, $state) and find the longitude, latitude and zip code.

This uses the Yahoo! API geocoding service.

Here is the snippit of code I acquired from [a href=\"http://www.mapki.com/index.php?title=Batch_Geocode_Addresses\" target=\"_blank\"]MAPKI[/a]
$url = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=xxxxxxxxxxx&street=".$address."&city=".$city."&state=".$state."";


$myFile = new XMLParser($url);

$xmlRoot = $myFile->data[0];  


if (sizeof($xmlRoot) > 0 ) {
        $geoLocation = $xmlRoot['child'];
        if (sizeof($geoLocation) > 0) {
                $geoLocationProperties = $geoLocation[0]['child'];
                for ($i = 0; $i < sizeof($geoLocationProperties); $i++) {
                        //echo $geoLocationProperties[$i]['name'] . " = " . $geoLocationProperties[$i]['content']."<br/>";
                    $map_data[strtolower($geoLocationProperties[$i]['name'])] = $geoLocationProperties[$i]['content'];
                }
        }
}
$long = $map_data['longitude'];
$lat = $map_data['latitude'];
$zip = $map_data['zip'];
I acquired my own appid and embedded the code in my page. I have a form that passes variables to this page. 3 of which are $address, $city and $state. When I submit my form, I get the following error:

Fatal error: Cannot instantiate non-existent class: xmlparser in /home2/tsiedsma/public_html/crappyfiles/map2/update.php on line 20

Line 20:
$myFile = new XMLParser($url);

Here is the code up to and including the yahoo api code I included.
<?
include 'dbax.php';

# grab the POST variables from the HTML form,
# put them into PHP variables so we can work with them
$name = $_POST['name'];
$address = $_POST['address'];
$city = $_POST['city'];
$state = $_POST['state'];
$phone = $_POST['phone']; 
$email = $_POST['email']; 
$ur = $_POST['ur']; 
$status = $_POST['status']; 
$ip = $_SERVER['REMOTE_ADDR']; 
$approved = $_POST['approved']; 

$url = "http://api.local.yahoo.com/MapsService/V1/geocode?appid=crappyfiles&street=".$address."&city=".$city."&state=".$state."";


$myFile = new XMLParser($url);

$xmlRoot = $myFile->data[0];  


if (sizeof($xmlRoot) > 0 ) {
        $geoLocation = $xmlRoot['child'];
        if (sizeof($geoLocation) > 0) {
                $geoLocationProperties = $geoLocation[0]['child'];
                for ($i = 0; $i < sizeof($geoLocationProperties); $i++) {
                        //echo $geoLocationProperties[$i]['name'] . " = " . $geoLocationProperties[$i]['content']."<br/>";
                    $map_data[strtolower($geoLocationProperties[$i]['name'])] = $geoLocationProperties[$i]['content'];
                }
        }
}
$lng = $map_data['longitude'];
$lat = $map_data['latitude'];
$zip = $map_data['zip'];

I don't understand what the error means or what I need to do to fix it. Help me please.

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,023 posts

Posted 09 March 2006 - 08:46 PM

You need to include the file that contains your xmlparser class definition.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 tsiedsma

tsiedsma
  • New Members
  • Pip
  • Newbie
  • 9 posts

Posted 09 March 2006 - 08:49 PM

I don't have one. I got that snippet of code from [a href=\"http://www.mapki.com/index.php?title=Batch_Geocode_Addresses\" target=\"_blank\"]http://www.mapki.com/index.php?title=Batch_Geocode_Addresses[/a].

I am just trying to make it work on my site.

What do I need to do?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users