0

如果地理定位成功(成功),如何调整函数内的缩放级别?

function createMap(lat, lng) {
var mapOptions = { center: new google.maps.LatLng(lat, lng), 
  zoom: 12,
  scrollwheel: false,
  mapTypeId: google.maps.MapTypeId.ROADMAP };
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);

function initialize() {
if(navigator.geolocation) {
  success = function(position) {
    createMap(position.coords.latitude, position.coords.longitude);
  };
  error = function() { createMap(99.648493, -99.410812); }

  navigator.geolocation.getCurrentPosition(success, error);
 }
}
4

1 回答 1

2

请检查以下代码以根据地理位置更改缩放级别:

 function createMap(lat, lng, zoomVal) {
 var mapOptions = { center: new google.maps.LatLng(lat, lng),    
zoom: zoomVal,   
scrollwheel: false,  
 mapTypeId: google.maps.MapTypeId.ROADMAP 
}; 
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);  
function initialize() { 
if(navigator.geolocation) {  
 success = function(position) {    
 createMap(position.coords.latitude, position.coords.longitude,15);  
 };   
error = function() {
 createMap(99.648493, -99.410812,12); 
}    
navigator.geolocation.getCurrentPosition(success, error);  
} 
} 
于 2012-07-02T06:57:38.720 回答