如何使用HTML5地理位置或Google API获取地址经纬度? [英] How do I get an addresses latitude-longitude using HTML5 geolocation or Google API?

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

问题描述

我感到困惑的是,我可以从Facebook获取用户的位置,我需要的只是获取该位置的经纬度,但我仍然找不到解决方案。

p>

如果我可以使用HTML5地理位置或任何Google API获取经度和纬度,这将有所帮助。什么是解决方案?

解决方案

 
if(navigator.geolocation){
navigator。 geolocation.getCurrentPosition(successFunction,errorFunction);
} else {
alert('看起来这个页面需要的地理位置,在您的浏览器中没有启用,请使用支持它的浏览器。

如果浏览器支持地理定位,并且 getCurrentPosition 成功运行,那么调用成功函数。然后在函数 successFunction

中有

$ p $
函数successFunction(position){
var lat = position.coords.latitude;
var long = position.coords.longitude;
console.log('你的纬度是:'+ lat +',经度是'+ long);
}

阅读更多关于Geolocation API的信息




I am getting baffled with a problem that is, I can get the location of a user from Facebook and all I need is to get the latitude and longitude of that location, but I still couldn't find a solution.

It will help if I can get that latitude and longitude using an HTML5 geolocation or any Google API. What is the solution?

解决方案

if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(successFunction, errorFunction);
} else {
    alert('It seems like Geolocation, which is required for this page, is not enabled in your browser. Please use a browser which supports it.');
}

If the browser supports geolocation and if getCurrentPosition runs successfully, then a success function is called. And then in the function successFunction

have


function successFunction(position) {
    var lat = position.coords.latitude;
    var long = position.coords.longitude;
    console.log('Your latitude is :'+lat+' and longitude is '+long);
}

Read more on the Geolocation API here

这篇关于如何使用HTML5地理位置或Google API获取地址经纬度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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