MySQL Forums
Forum List  »  PHP

Notice: Undefined offset in script
Posted by: Davor Ergotic
Date: March 26, 2012 05:06PM

Hi all,

need hlp please.
This is the case - function get full URL to Google Maps XML document [with all the parameters of searched address].

This is the code
function getcoordinates($location) {

	$mapaddress = urlencode("$location");


	// Desired address
	$key = MAPS_KEY;
	$url = "http://maps.google.com/maps/geo?q=$mapaddress&output=xml&key=$key";;
	

	// Retrieve the URL contents
	$page = file_get_contents($url);


	// Parse the returned XML file
	$xml = new SimpleXMLElement($page);
		
	// Parse the coordinate string
	list($longitude, $latitude, $altitude) = explode(",", $xml->Point->coordinates);

	print '<pre>'; print_r($xml->Point->coordinates); exit('</pre>'); 

	$geo['lat'] = $latitude;
	$geo['long'] = $longitude;
	$geo['alt'] = $altitude;
	
	return $geo;

}

With this code I get:
Notice: Undefined offset: 2 in ..../functions.php on line 36
Notice: Undefined offset: 1 in ..../functions.php on line 36
Line 36 is:
list($longitude, $latitude, $altitude) = explode(",", $xml->Point->coordinates);

Problem is that I don't get coordinates of searched address.

Please, help.
Thx in advance,
Davor

Options: ReplyQuote


Subject
Written By
Posted
Notice: Undefined offset in script
March 26, 2012 05:06PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.