开发者

determine if geolocation is ip based?

i'm playing with the google maps-api and want to show the visitor a message if the google maps geolocation is IP based and not from 开发者_开发问答wifi or gps. The reason is to tell them that the location is not that accurate... But i can't find a function for checking this.


One of the Google Maps Geocoding API parameters is sensor:

"sensor (required) — Indicates whether or not the geocoding request comes from a device with a location sensor. This value must be either true or false."

You will probably have to perform a check on the user environment to detect if it is using GPS, and then pass the value as a parameter for sensor. This can vary by the environment (at least I don't know how to make it platform neutral).

Another possibility is using Google ClientLocation, which I believe only uses the IP-based location. You can then compare this to the value you have. If they're the same, then you know.


I do not believe there is a mechanism inside of Google Maps API v3 to determine how the position was obtained. But you can use the accuracy property to find out how accurate the position is and then alert your users if it is above a threshold that you set.

The accuracy property is specified in meters. So a smaller number means the position that you have received is more accurate.

Here's an example:

navigator.geolocation.getCurrentPosition(
    function(position) { alert(position.coords.accuracy); },
    function() {alert("failure"); },
    {enableHighAccuracy:true});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜