我正在使用此功能与谷歌地图
var currgeocoder;
navigator.geolocation.getCurrentPosition(function (position, html5Error) {
geo_loc = processGeolocationResult(position);
currLatLong = geo_loc.split(",");
initializeCurrent(currLatLong[0], currLatLong[1]);
});
function processGeolocationResult(position) {
html5Lat = position.coords.latitude; //Get latitude
html5Lon = position.coords.longitude; //Get longitude
html5TimeStamp = position.timestamp; //Get timestamp
html5Accuracy = position.coords.accuracy; //Get accuracy in meters
return html5Lat + ", " + html5Lon;
}
alert(html5Lat);
如您所见,我没有使用var
将变量设为全局变量,但alert()
不起作用,如果我将alert()
置于函数内部,则效果很好。那么如何从另一个函数访问html5lat
和html5lon
全局?