从Lat / Long值返回英格兰,苏格兰等而不是英国

时间:2011-07-19 14:59:38

标签: google-maps geolocation google-maps-api-3

我需要知道用户是从英格兰,苏格兰,爱尔兰还是其他地方访问我的Lat / Long值。

但是,我一直在使用Google Maps API,但这会返回英国。

有没有办法在Google地图上执行此操作,还是有其他API会返回各个国家/地区?

2 个答案:

答案 0 :(得分:1)

您可以为每个区域定义边界多边形,然后检查纬度/经度点是否在内部。

https://github.com/tparkin/Google-Maps-Point-in-Polygon

答案 1 :(得分:0)

尝试geocode

我用过

var gc = new google.maps.Geocoder();
gc.geocode({'location': ll}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
            if (results[0]) {       
                var results = results[0].address_components;
            }
        }
    });

结果如下:

results[0].formatted_address: "275-291 Bedford Ave, Brooklyn, NY 11211, USA",
results[1].formatted_address: "Williamsburg, NY, USA",
results[2].formatted_address: "New York 11211, USA",
results[3].formatted_address: "Kings, New York, USA",
results[4].formatted_address: "Brooklyn, New York, USA",
results[5].formatted_address: "New York, New York, USA",
results[6].formatted_address: "New York, USA",
results[7].formatted_address: "United States"