2011-09-27 52 views
1

我遇到了一個問題,無法與我的谷歌地圖一起工作。所有標記都指向正確的座標,但是當它們出現在地圖上時,自動縮放無法正確調整。請有人可以幫助我與我的var範圍請。var bounds無法在我的谷歌地圖上工作

var companyLocale = new google.maps.LatLng(33.206060, -117.111951); 
var noGeo = new google.maps.LatLng(40.69847032728747, -73.9514422416687); 


function initialize() { 
    var myOptions = { 
    zoom: 14, 
    mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 

    <!-------------------------------USER MARKERS-------------------> 
    var usericon = new google.maps.MarkerImage(
    'images/userimage.png', 
    new google.maps.Size(48,48), 
    new google.maps.Point(0,0), 
    new google.maps.Point(24,48) 
); 

    var usershadow = new google.maps.MarkerImage(
    'images/usershadow.png', 
    new google.maps.Size(76,48), 
    new google.maps.Point(0,0), 
    new google.maps.Point(24,48) 
); 
    <!-------------------------------COMP MARKERS-------------------> 
    var icon = new google.maps.MarkerImage(

    'images/image.png', 
    new google.maps.Size(48,48), 
    new google.maps.Point(0,0), 
    new google.maps.Point(24,48) 
); 

    var shadow = new google.maps.MarkerImage(
    'images/shadow.png', 
    new google.maps.Size(76,48), 
    new google.maps.Point(0,0), 
    new google.maps.Point(24,48) 
); 

function toggleBounce() { 

    if (marker.getAnimation() != null) { 
     marker.setAnimation(null); 
    } else { 
     marker.setAnimation(google.maps.Animation.BOUNCE); 
    } 
    } 

    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 

    // Safari supports the W3C Geolocation method 
    if(navigator.geolocation) { 
    navigator.geolocation.getCurrentPosition(function(position) { 
     initialLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude); 

     var bounds = new google.maps.LatLngBounds(); 
     var placeMarker = new google.maps.Marker({ 
     position: initialLocation, 
     icon: usericon, 
     shadow: usershadow, 
     animation: google.maps.Animation.DROP, 
     map: map 
     }); 
     map.setCenter(initialLocation); 

     var bounds = new google.maps.LatLngBounds(); 
     var Marker = new google.maps.Marker({ 
     position: companyLocale, 
     icon: icon, 
     shadow: shadow, 
     animation: google.maps.Animation.DROP, 
     map: map 
     }); 

     google.maps.event.addListener(Marker, 'click', function() { 
     window.location = "main-export/main.html"; 
}); 
     google.maps.event.addListener(placeMarker, 'click', function() { 
     window.location = "main-export/loyalty.html"; 
}); 

    }, function() { 
     handleNoGeolocation(browserSupportFlag); 
    }); 
    } else { 
    // Browser doesn't support Geolocation 
    handleNoGeolocation(); 
    } 

    function handleNoGeolocation() { 
    initialLocation = noGeo; 
    map.setCenter(initialLocation); 
    } 
    bounds.extend(myLatLng); 
    map.fitBounds(bounds); 
} 
+0

您好,我希望有人會有些見識到我在做什麼不正確。就像我之前提到的,我只需要讓var邊界正常工作。 – need2nobasis

回答

1

您有bounds.extend(myLatLng);但myLatLng無處創建。你似乎只有兩個標記,所以你應該只需要調用兩次界限,每次界定一次。

更換bounds.extend(myLatLng);

bounds.extend(companyLocale); 
bounds.extend(initialLocation);