【问题标题】:navigator.geolocation.getCurrentPosition return differently between firefox and chrome?navigator.geolocation.getCurrentPosition 在 firefox 和 chrome 之间返回不同?
【发布时间】:2011-11-15 08:17:01
【问题描述】:

我有一个sn-p

navigator.geolocation.getCurrentPosition(function(position) { 
        // do somehthing
});

但返回的结果在 chrome 和 firefox 之间是不同的。 chrome中的位置没有地址属性。

有人可以帮忙吗?

谢谢

【问题讨论】:

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


【解决方案1】:

看起来 Firefox 在位置界面方面有点领先。该标准目前不支持地址属性。

Geolocation API specifications:

Position 接口是地理定位的容器 此 API 返回的信息。这个版本的规范 允许一个坐标类型的属性和一个时间戳。未来 API 的版本可能允许提供其他属性的其他属性 有关此职位的信息(例如街道地址)。

getCurrentPosition() 方法返回的位置对象包含一个带有经纬度的坐标属性。

navigator.geolocation.getCurrentPosition(function(position) { 
    var lat = position.coords.latitude;
    var lng = position.coords.longitude;        

    // do something with lat and lng
});

如果您需要街道地址,您将不得不使用地理编码服务(如Google Maps Geocoder,即Firefox is using to find the address)来查找地址。

【讨论】: