如何使用纬度&经度? [英] How do I get location name or city using latitude & longitudes?

查看:150
本文介绍了如何使用纬度&经度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的代码,但是如何从经度&域名获取城市名称或地点名称,纬度?

I'm using the below code, but how to get the city name or the location name from the longitude & latitude?

var x=document.getElementById("location");
function getLocation()
{
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(showPosition,showError);
    }
    else {
        x.innerHTML="Geolocation is not supported by this browser.";
    }
}

function showPosition(position)
{
    x.innerHTML="Latitude: " + position.coords.latitude + 
        "<br>Longitude: " + position.coords.longitude;  
}


推荐答案

您可以使用Google地图v3 API在经度和纬度对上执行反向地理编码。您可以在这里找到如何执行此操作的示例: https://developers.google.com/maps/documentation / geocoding /#ReverseGeocoding

You can use the Google Maps v3 API to perform reverse geocoding on a latitude and longitude pair. You can find an example of how to do that here: https://developers.google.com/maps/documentation/geocoding/#ReverseGeocoding.

这篇关于如何使用纬度&amp;经度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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