开发者

html5 geolocation tracking

开发者 https://www.devze.com 2023-01-23 16:41 出处:网络
I am new to html 5 geolocation,Is there any site or exampleswhere it shows how, i can use html geolocation api to track the location of other devices. Also, for example how can i use use HTML5geolocat

I am new to html 5 geolocation, Is there any site or examples where it shows how, i can use html geolocation api to track the location of other devices. Also, for example how can i use use HTML5 geolocation to find the nearest car dealer say 5 or 10 m开发者_运维知识库iles from me? Any examples sample would be really helpfull.

thanks


I can't speak to tracking devices, but i've been writing something that might help with the second part of your question.

    //check browser support
    if(navigator.geolocation) {
    //do the geolocation stuff
    navigator.geolocation.getCurrentPosition(function(position) {
        //make a string out of the coordinates
        var initloc_str = position.coords.latitude + ', ' + position.coords.longitude;
        //pass it to a function that searches for donut shops near the coordinates
        donutSearch(initloc_str);
    });
    } else { // if no browser support, error message or whatever

My donut shop search function is based on the local search in Google's Ajax search API, I found this article on webmonkey helpful for that bit. That API was recently deprecated but I haven't figured out how to do local search with their new Custom Search API yet.


You can register a function for tracking positions of a user:

var watchId = navigator.geolocation.watchPosition(function(position) {  
  console.log(position.coords.latitude);
  console.log(position.coords.longitude);
});

And you can unregister:

navigator.geolocation.clearWatch(watchId);


This site will give you a awesome overview of the HTML5 geolocation Capability.

0

精彩评论

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