我正在尝试制作一个显示谷歌地图的简单页面,以当前位置为中心。
我已经能够通过以下方式成功获得纬度/经度,我也将其存储在 localStorage 中。:
var geooptions = {timeout: 10000, maximumAge: 11000, enableHighAccuracy: true };
var geofail = function(){
alert("Geolocation failed. \nPlease enable GPS in Settings.");
};
var geosuc = function(p){
localStorage.lat = p.coords.latitude;
localStorage.lon = p.coords.longitude;
localStorage.latlon = p.coords.latitude + ', ' + p.coords.longitude;
};
var getLocation = intel.xdk.geolocation.watchPosition(geosuc,geofail,geooptions);
var stopGeolocation = function(){
intel.xdk.geolocation.clearWatch(geolocationWatchTimer);
}
当我尝试用它绘制地图时,什么也没有发生 - 我有一个 id="page_4" 的 div:
function drawMap() {
//Creates a new google maps object
var latlng = new google.maps.LatLng(localStorage.lat, localStorage.lon);
myLatLng = latlng;
var mapOptions = {
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
zoomControl: true,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.SMALL,
position: google.maps.ControlPosition.LEFT_TOP
},
};
var mymap = new google.maps.Map(document.getElementById("page_4"), mapOptions);
}