Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何从纬度和经度获取包含国家、城市和街道名称的字符串_Javascript_Asp.net Mvc - Fatal编程技术网

Javascript 如何从纬度和经度获取包含国家、城市和街道名称的字符串

Javascript 如何从纬度和经度获取包含国家、城市和街道名称的字符串,javascript,asp.net-mvc,Javascript,Asp.net Mvc,我如何通过要求Lat和Lon查找州名、街道名和街道号,或者仅查找Lat和Lon的完整地址来实现功能?如果您使用的是谷歌地图,您可以尝试使用地理编码器根据坐标获取地址。就这样, var currentLatitude = ...; var currentLongitude = ...; var geocoder = new google.maps.Geocoder; var latlng = { lat: currentLatitude, lng: currentLongitude }; g

我如何通过要求Lat和Lon查找州名、街道名和街道号,或者仅查找Lat和Lon的完整地址来实现功能?如果您使用的是谷歌地图,您可以尝试使用
地理编码器
根据坐标获取地址。就这样,

var currentLatitude = ...;
var currentLongitude = ...;

var geocoder = new google.maps.Geocoder;

var latlng = { lat: currentLatitude, lng: currentLongitude };

geocoder.geocode({ 'location': latlng }, function (results, status) {
    if (status === 'OK') {
        // address
        console.log(results);
    } else {
        console.log('Geocoder failed due to: ' + status);
    }
});

默认情况下,您不能这样做。您需要找到第三方库才能执行此操作。^我建议使用谷歌地图API。