Googlemaps 反向地理编码获取国家/地区名称、英国国家/地区

发布于 2024-10-21 03:38:54 字数 1221 浏览 5 评论 0原文

我正在使用谷歌地图 Api V3 并使用反向地理编码来查找点击的国家/地区的名称。 这似乎对除英国境内的国家/地区之外的大多数国家/地区都适用。

英国由英格兰、苏格兰、威尔士和北爱尔兰组成,这是 4 个独立的国家,但谷歌地图(以及大多数其他国家的地图)将它们全部视为“英国”。

我需要知道英国境内的哪个特定国家/地区被点击,而不仅仅是英国被点击!

我正在使用以下 javascript,目前仅使用 Visual Studios“观看”功能来深入研究“结果[1]”以查看其中包含的内容。

  function initialize() {
    geocoder = new google.maps.Geocoder();
    var latlng = new google.maps.LatLng(51.8052184317649, -4.965819906250006);
    var myOptions = {
        zoom: 5,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

    google.maps.event.addListener(map, 'click', function (event) {
        if (confirm('Is this the location you would like to you for your company?')) {

            geocoder.geocode({ 'latLng': event.latLng }, function (results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    if (results[1]) {

                    }
                }
            });
 }
        });
    }

如果我在地图缩放得很远时单击,国家名称(即威尔士)会返回类型“administrative_area_level_1”和“political”,但是当您放大时,它不再存在,因为它只给出不包含“的地址”威尔士”。

有谁知道我如何解决这个问题?我相信其他英国人也遇到过这个吗?

I am using google maps Api V3 and using reverse geocoding to find the name of a country clicked on.
This appears to work fine for most countries except the countries within the UK.

The UK consists of England, Scotland, Wales and Northern Ireland, which are 4 separate countries, but google maps (and most other country things) see them all as just "UK".

I need to know which particular country within the UK has been clicked and not just that the UK has been clicked!

I am using the following javascript and I am currently just using visual studios "watch" feature to dig down into "results[1]" to see what is contained.

  function initialize() {
    geocoder = new google.maps.Geocoder();
    var latlng = new google.maps.LatLng(51.8052184317649, -4.965819906250006);
    var myOptions = {
        zoom: 5,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

    google.maps.event.addListener(map, 'click', function (event) {
        if (confirm('Is this the location you would like to you for your company?')) {

            geocoder.geocode({ 'latLng': event.latLng }, function (results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                    if (results[1]) {

                    }
                }
            });
 }
        });
    }

If I click when the map is zoomed quite far out the country name (ie Wales) comes back with types "administrative_area_level_1" and "political" but when you zoom in it's no longer there as it just gives the address which doesn't contain "Wales".

Does anyone know how I get round this? I'm sure other Brits have come across this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

〆凄凉。 2024-10-28 03:38:54

无法弄清楚如何反向地理编码以获取英国国家/地区,因为我认为这实际上是不可能的!

最终使用邮政编码并以此确定国家/地区!
不是最好的,但它对我有用!

Couldn't work out how to reverse geocode to get a UK country as I think it's actually impossible!

Ended up using postcodes and working out countries by that!
Not the best, but it works for me!

流云如水 2024-10-28 03:38:54

英国国家/地区表示为 administrative_area_level_1 结果,请查看本示例中的倒数第二个结果(不要依赖 address_components):

https://maps.googleapis.com/maps/api/geocode/json?&latlng =51.641033,-0.647507

UK countries are represented as administrative_area_level_1 results, look at the 2nd last result in this example (do not rely on address_components for this):

https://maps.googleapis.com/maps/api/geocode/json?&latlng=51.641033,-0.647507

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文