解析谷歌地图API
似乎无法让这个解析器适用于谷歌地图,我认为这是因为没有 xml 扩展名?它适用于我制作的 xml 文件,但是当我使用 google xml 时,它似乎不想抓取它。
<?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;
?>
can't seem to get this 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;
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以改变这个:
到这个
You could change this:
to this
通常,Google API 需要 API 密钥。我没有看到您将其添加到您的请求中的位置。当我手动构建您的 api 调用并将其粘贴到浏览器中时,我得到以下信息: http://maps.google.com/maps/api/geocode/xml?address=edgemont%20dr%20wyoming%2C%20MI 并且 Google 返回“请求被拒绝”。
您可以转到此处获取 Google 地图 API 密钥。也就是说,还有很多很多其他的地理编码器。有些需要某种类型的注册和/或付款,有些则不需要。
这里是 Google 的“免费 GeoCoder 服务” ”
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"