对一组坐标进行反向地理编码
我有以下格式的坐标集
(-33.9,18.6)
我如何获取这些坐标最近的城镇或国家/地区的名称?我猜它会涉及 Javascript,但如果合适的话我很高兴也使用 PHP?
编辑:我正在尝试 Google 反向地理编码器,但遇到问题它。下面的代码与他们的示例之一非常相同,但似乎根本没有运行......有什么想法吗?
<script type="text/javascript" charset="utf-8">
function reverseGeocode(lat,lon){
var geocoder = new GClientGeocoder();
var latlng = new GLatLng(lat, lon);
geocoder.getLocations(latlng, function(addresses) {
alert(addresses);
});
}
</script>
I have sets of co-ordinates in the following format
(-33.9,18.6)
How do I go about getting the name of the nearest town or Country for those co-ords? I'm guessing it will involve Javascript, but am happy to also use PHP if appropriate?
EDIT: Am trying the Google Reverse Geocoder but having trouble with it. The following code is pretty identical to one of their examples but doesn't seem to be running at all... any ideas why?
<script type="text/javascript" charset="utf-8">
function reverseGeocode(lat,lon){
var geocoder = new GClientGeocoder();
var latlng = new GLatLng(lat, lon);
geocoder.getLocations(latlng, function(addresses) {
alert(addresses);
});
}
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
google 有一个网络服务,您可以调用它来进行(反向)地理编码,它比使用完整的 javascript api 轻量得多。
v2 的示例:http://maps.google.com/maps/geo?q=51,4&sensor=false&output=json&key=insert_your_api_key_here&callback=parseme
并使用 v3:
http://maps.google.com google.com/maps/api/geocode/json?latlng=51,4&sensor=false&callback=parseme
在这两种情况下,您都会得到 json 响应(javascript 对象),区别在于现在已弃用v2 你需要提供你的 api 密钥,你可以使用回调(为了跨站点 ajax 的优点),它可以大声喊出来 v3 不再支持(但您不再需要 api 密钥)。
google has a webservice you can call to do (reverse) geocoding, which is much more lightweight then using the full javascript api.
an example with v2: http://maps.google.com/maps/geo?q=51,4&sensor=false&output=json&key=insert_your_api_key_here&callback=parseme
and with v3:
http://maps.google.com/maps/api/geocode/json?latlng=51,4&sensor=false&callback=parseme
in both cases you get a json response (javascript object), the difference being that in the now deprecated v2 you need to provide you api key and you can use a callback (for cross site ajax goodness) which for crying out loud isn't supported in v3 any more (but you don't need an api key any more).
Google 地图 API 有一个 JavaScript 示例。
http://code.google.com/apis/maps/documentation/ services.html#ReverseGeocoding
Google maps API has a javascript example.
http://code.google.com/apis/maps/documentation/services.html#ReverseGeocoding
您注册了他们的 API 密钥吗?
还有具体的错误信息吗?
Have you registered for their API key?
Also are there any specific error messages?
好的,成功让它工作了,所以这就是我所做的:
Ok managed to get it working, so here's what I did: