parse google maps API
can't seem to get t开发者_运维技巧his parser to work for google maps, I think its because there is no xml extension? It works on a xml file that I make, but when I use google xml it doesn't seem to want to grab it.
<?php
$address = 'edgemont dr wyoming, MI';
$address = rawurlencode ($address);
$url = 'http://maps.google.com/maps/api/geocode/xml?address=' . $address . '&sensor=false';
$link = '<a href="' . $url . '">' . $url . '</a>';
echo $link;
$xml = simplexml_load_file($url);
// get Latitude from XML
$lat=$xml->GeocodeResponse->result->geometry->location->lat;
echo $lat;
?>
You could change this:
// get Latitude from XML
$lat=$xml->GeocodeResponse->result->geometry->location->lat;
echo $lat;
to this
// get Latitude from XML
$lat=$xml->result->geometry->location->lat;
echo $lat;
normally, google API's require an API key. I am not seeing where you are adding that to your request. when I manually construct your api call and past it into my browser, i get this: http://maps.google.com/maps/api/geocode/xml?address=edgemont%20dr%20wyoming%2C%20MI and google returns a "Request Denied".
you can go here to get a Google Maps API key. That said, there are many many many other geo-coders out there. some require some type of registration and/or payment and others do not.
here is a google of "Free GeoCoder services"
精彩评论