這裏是我的代碼,而不類別:
var map = null;
var ERROR_MESSAGES = {
GPS_OFF: "please turn on GPS from your settings.",
GPS_TIME_OUT: "maybe you are in a building or something, get into an open area.",
GPS_UNKOWN: "Error happened while getting location, please try again later."
};
var geolocationManager = new GeolocationManager();
function success(position) {
var coords = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
var options = {
zoom: 18,
center: coords,
mapTypeControl: false,
disableDefaultUI: true,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.SMALL
},
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("mapcontainer"), options);
var marker = new google.maps.Marker({
position: coords,
map: map,
icon:'e-pin.png',
animation:google.maps.Animation.BOUNCE
});
}
function findPosition(onSuccess) {
geolocationManager.isLocationEnabled(function (isEnabled) {
if (!isEnabled) {
Util.Alert(ERROR_MESSAGES.GPS_OFF);
return;
}
geolocationManager.find(onSuccess, function (e) {
Util.Alert(ERROR_MESSAG`enter code here`ES.GPS_UNKOWN);
});
}, function (e) {
geolocationManager.find(onSuccess, function (e) {
Util.Alert(ERROR_MESSAGES.GPS_UNKOWN);
});
});
}
function watchPosition() {
geolocationManager.watch();
}
findPosition(success);
function getLocation() {
if (!map)
findPosition(success);
else
findPosition(showPosition);
/*if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}*/
}
function setCurrentPosition() {
findPosition(function (position) {
var coords = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
map.panTo(coords);
});
}
function showPosition(position) {
map.setCenter(new google.maps.LatLng(position.coords.latitude,position.coords.longitude));
}
此意見不是有用的或它與問題沒有關係。 – Drako 2017-01-26 11:17:06