我能否知道坐标是否在城市内部? [英] Can I find out if a coordinate is inside a city?

查看:78
本文介绍了我能否知道坐标是否在城市内部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个LatLng对象,是否有任何方法检查它是否代表城市内可能的位置?我怎样才能得到一个城市的极限?
我使用Google Map V3。

解决方案

您是否尝试过反向地理编码? b

http://code.google .com / apis / maps / documentation / javascript / services.html#ReverseGeocoding



您可以查看格式化的地址,重新寻找。我不确定这对您的应用程序有多准确,但它是一个选项。


$ b

  (),
latlng = new google.maps.LatLng(40.730885,-73.997383);
geocoder.geocode({'latLng':latlng},function(results,status){
if(status == google.maps.GeocoderStatus.OK){
if(results [1 ]){
console.log(results [1]);
console.log(results [1] .formatted_address);
}
} else {
alert (Geocoder失败,原因是:+状态);
}
});
}


Let's say I have a LatLng object, is there any way of checking if it represents a possible location within a city? How can I get the limits of a city? I'm using Google Map V3.

解决方案

Have you tried reverse geocoding?

http://code.google.com/apis/maps/documentation/javascript/services.html#ReverseGeocoding

You could check the formatted address to see if the city matches what you're looking for. I'm not sure how accurate this will be for your application, but it's an option.

function codeLatLng() {
    var geocoder = new google.maps.Geocoder(),
        latlng = new google.maps.LatLng(40.730885, -73.997383);
    geocoder.geocode({ 'latLng': latlng }, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            if (results[1]) {
                console.log(results[1]);
                console.log(results[1].formatted_address);
            }
        } else {
            alert("Geocoder failed due to: " + status);
        }
    });
}

这篇关于我能否知道坐标是否在城市内部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆