I've got some code that takes any address and returns lat and long as a php variable.
if ($_SESSION['where']) { $where = stripslashes($_SESSION['where']); $whereurl = urlencode($where); $location = file("http://maps.google.com/maps/geo?q=new+york+New+york &output=csv&key=xxxxxxxxxxxxxxxxxxxxxxxx"); list ($stat,$acc,$north,$east) = explode(",",$location[0]); $html = "Information for ".$where."<br>"; $html .= "North: $north, East: $east<br>"; $html .= "Accuracy: $acc, Status: $stat<br>"; } else { $html = "Varibles Undefined"; } ?> <?php $_SESSION['lat'] = "$html"; $_SESSION['lon'] = "$whereurl"; echo"<strong>"?><?php echo "$north";?>° North, <?php echo "$east";?>° East</strong> I know it works because when I enter
http://maps.google.com/maps/geo?q=$whereurl &output=csv&key=xxxxxxxxxxxxxxxxxxxx manually into a browser, it returns
200,4,40.7143528,-74.0059731 which is what I need saved as a PHP variable. However it's not saving it as $north or $east. Any suggestions on how to fix this? Thank's in advance.
here's what it gives me:
{ "name": "new york new york", "Status": { "code": 200, "request": "geocode" }, "Placemark": [ { "id": "p1", "address": "New York, NY, USA", "AddressDetails": { "Accuracy" : 4, "Country" : { "AdministrativeArea" : { "AdministrativeAreaName" : "NY", "SubAdministrativeArea" : { "Locality" : { "LocalityName" : "New York" }, "SubAdministrativeAreaName" : "New York" } }, "CountryName" : "USA", "CountryNameCode" : "US" } }, "ExtendedData": { "LatLonBox": { "north": 40.8495342, "south": 40.5788964, "east": -73.7498543, "west": -74.2620919 } }, "Point": { "coordinates": [ -74.0059731, 40.7143528, 0 ] } }, { "id": "p2", "address": "Manhattan, New York, NY, USA", "AddressDetails": { "Accuracy" : 4, "Country" : { "AdministrativeArea" : { "AdministrativeAreaName" : "NY", "SubAdministrativeArea" : { "Locality" : { "DependentLocality" : { "DependentLocalityName" : "Manhattan" }, "LocalityName" : "New York" }, "SubAdministrativeAreaName" : "New York" } }, "CountryName" : "USA", "CountryNameCode" : "US" } }, "ExtendedData": { "LatLonBox": { "north": 40.8200450, "south": 40.6980780, "east": -73.9033130, "west": -74.0351490 } }, "Point": { "coordinates": [ -73.9662495, 40.7834345, 0 ] } } ] }
manually into a browser, it retrunsmay be it has an empty line in front. Try to replacefilewithfile_get_contentsand remove[0]after$locationvar_dump($location);var_dump($location);after the line withfileand check the output.