如何获取纬度和经度值?
Posted
技术标签:
【中文标题】如何获取纬度和经度值?【英文标题】:How can I get the latitude and longitude values? 【发布时间】:2015-07-06 13:42:12 【问题描述】:如何获取纬度和经度值。 然后在没有地图的情况下在屏幕上显示值。
我使用代码:
function success(position)
var s = document.querySelector('#status');
if (s.className == 'success')
// not sure why we're hitting this twice in FF, I think it's to do with a cached result coming back
return;
s.innerhtml = "found you!";
s.className = 'success';
var mapcanvas = document.createElement('div');
mapcanvas.id = 'mapcanvas';
mapcanvas.style.height = '400px';
mapcanvas.style.width = '560px';
document.querySelector('article').appendChild(mapcanvas);
var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
var myOptions =
zoom: 15,
center: latlng,
mapTypeControl: false,
navigationControlOptions: style: google.maps.NavigationControlStyle.SMALL,
mapTypeId: google.maps.MapTypeId.ROADMAP
;
var map = new google.maps.Map(document.getElementById("mapcanvas"), myOptions);
var marker = new google.maps.Marker(
position: latlng,
map: map,
title:"You are here! (at least within a "+position.coords.accuracy+" meter radius)"
);
function error(msg)
var s = document.querySelector('#status');
s.innerHTML = typeof msg == 'string' ? msg : "failed";
s.className = 'fail';
// console.log(arguments);
if (navigator.geolocation)
navigator.geolocation.getCurrentPosition(success, error);
else
error('not supported');
【问题讨论】:
logicify.github.io/jquery-locationpicker-plugin 参考这个***.com/questions/10512537/… “没有地图”是什么意思?您想从发布的代码中删除地图吗? 【参考方案1】:使用你的成功方法的位置对象来获取纬度和经度值;
alert("Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude)
参考:http://www.w3schools.com/html/tryit.asp?filename=tryhtml5_geolocation
【讨论】:
以上是关于如何获取纬度和经度值?的主要内容,如果未能解决你的问题,请参考以下文章
如何从android中的纬度和经度获取完整的地址? [复制]