HTML5地理位置实施 [英] HTML5 Geolocation implementation

查看:77
本文介绍了HTML5地理位置实施的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个地区列表和经度/纬度,我要求用户在他们打我的网站时选择他们的位置。如果可能的话,我希望使用HTML5的地理位置预先填充其位置,但我并不完全确定实现该目标的最佳方式。网络上似乎缺乏教程,至少从我能找到的东西来看。有没有人做过这个?你知道一个很好的教程/资源吗?



更新



有一堆城市的坐标,我该如何使用javascript来确定最近的位置?

试试这个例子:

  window.onload = function(){
if(navigator.geolocation)
navigator.geolocation.getCurrentPosition(handleGetCurrentPosition ,onError);
}

函数handleGetCurrentPosition(位置){

location.coords.latitude;
location.coords.longitude;

函数onError(){...}

一个更大的演示。 http://od-eon.com/labs/geolocation/


I have a list of areas and lattitude/longitude which I'm asking the user to select their location when they hit my site. I'd like to have their location prefilled using HTML5's geolocation if possible, but I'm not exactly sure the best way to do that. There seems to be a lack of tutorials on the web, at least from what I can find. Has anyone done this? Do you know of a good tutorial/resource?

update

If I have coordinates of bunch of cities, how can I use javascript to determine the closest location?

解决方案

Try this example:

window.onload = function(){
    if(navigator.geolocation)
        navigator.geolocation.getCurrentPosition(handleGetCurrentPosition, onError);
}

function handleGetCurrentPosition(location){

    location.coords.latitude;
    location.coords.longitude;
}
function onError(){...}

Go here for a larger demo. http://od-eon.com/labs/geolocation/

这篇关于HTML5地理位置实施的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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