我试图做一些事情,应该是很简单 - 但它做我的头 我似乎无法得到一个变量从一个函数返回使用Javascript - 返回变量失败
var where;
if (navigator.geolocation) {
where = navigator.geolocation.getCurrentPosition(function (position) {
// okay we have a placement - BUT only show it if the accuracy is lower than 500 mtrs
//if (position.coords.accuracy <= 500) {
// put their lat lng into google
var meLatLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
var image = "images/map_blue.png";
var myMarker = new google.maps.Marker({
position: meLatLng,
map: map,
title: "Your location, as provided by your browser",
icon: image,
zIndex: 50
});
//} // end 500 mtrs test
return meLatLng;
});
alert("A: "+where);
}
我有一个名为全局变量在哪里,我想用navigator.geolocation从浏览器接收经纬度信息,以填补它 - 它绘制在地图上的用户 - 但警报(在哪里)总是返回undefined
什么我做错了吗?
是的,它似乎它用完主流,所以我不得不看看这个CallBack的想法..谢谢:) – keranm 2010-10-04 18:40:01