tsiedsma Posted March 9, 2006 Share Posted March 9, 2006 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][code]$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'];[/code]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:[b]Fatal error[/b]: Cannot instantiate non-existent class: xmlparser in [b]/home2/tsiedsma/public_html/crappyfiles/map2/update.php[/b] on line [b]20[/b]Line 20:[code]$myFile = new XMLParser($url);[/code]Here is the code up to and including the yahoo api code I included.[code]<?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'];[/code]I don't understand what the error means or what I need to do to fix it. Help me please. Link to comment https://forums.phpfreaks.com/topic/4552-need-help-with-adding-some-code-to-working-page/ Share on other sites More sharing options...
Barand Posted March 9, 2006 Share Posted March 9, 2006 You need to include the file that contains your xmlparser class definition. Link to comment https://forums.phpfreaks.com/topic/4552-need-help-with-adding-some-code-to-working-page/#findComment-15905 Share on other sites More sharing options...
tsiedsma Posted March 9, 2006 Author Share Posted March 9, 2006 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? Link to comment https://forums.phpfreaks.com/topic/4552-need-help-with-adding-some-code-to-working-page/#findComment-15907 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.