【问题标题】:How to find city name with latitude and longitude in JavaScript?如何在 JavaScript 中查找带有经纬度的城市名称?
【发布时间】:2016-11-24 17:04:34
【问题描述】:

我已经在很多网站上搜索了解决方案,但没有一个有效。

从几个小时以来,我一直在尝试使用 latitude 和 longitude 值来获取 城市名称,这些值将从输入框中获取到我的 xy 变量,但没有示例有效。

我也读过 Google maps API,但没用。

我已经有一个 API 密钥。

你有什么解决办法吗?

这个例子我从网站上得到并尝试但没有成功:

function myFunction() { var x='xxxxx'; var y='xxxxx'; //my coordinates 
    var geocoder = new google.maps.Geocoder;
    var latlng = {lat: parseFloat(x), lng: parseFloat(y)};

    geocoder.geocode({'location': latlng}, function(results, status) {
        if (status === google.maps.GeocoderStatus.OK) {
        // ...
        } else {
            window.alert('No results found');
        }
        } else {
            window.alert('Geocoder failed due to: ' + status);
        }
    });
}

【问题讨论】:

标签: javascript google-maps geolocation latitude-longitude city


【解决方案1】:
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-26
  • 1970-01-01
  • 1970-01-01
  • 2017-10-17
  • 1970-01-01
相关资源
最近更新 更多