2013-03-08 83 views
0

截圖:http://imageshack.us/a/img59/8541/72825985.png谷歌地圖JS API V3單一標誌物多圈

以上的結果是由多個標記在同一地點交付(不同半徑)。

我想一次拖動一個標記,而不是多個標記。

其次,infowindow可用於不同的半徑。

任何幫助,非常感謝!

var locations = [ 
    ['US gov suggested', 1.8833, 102.7833, 5, 'green', 80000], 
    ['agricultural contamination', 1.8833, 102.7833, 4, 'blue', 60000], 
    ['Chernobyl_Exclusion_Zone (fallout)', 1.8833, 102.7833, 3, 'yellow', 30000], 
    ['Fukushima evacuation zone', 1.8833, 102.7833, 2, 'red', 20000], 
    ['emergency zone', 1.8833, 102.7833, 1, 'black', 5000] 

]; 

var infowindow = new google.maps.InfoWindow(); 

var marker, i; 

for (i = 0; i < locations.length; i++) { 
    marker = new google.maps.Marker({ 
    position: new google.maps.LatLng(locations[i][1], locations[i][2]), 
    draggable: true, 
    map: map 
    }); 

    google.maps.event.addListener(marker, 'click', (function(marker, i) { 
    return function() { 
     infowindow.setContent(locations[i][0]); 
     infowindow.open(map, marker); 
    } 
    })(marker, i)); 

var circle = new google.maps.Circle({ 
     map: map, 
     fillColor:locations[i][4], 
     //fillOpacity:0.3, 
     //strokeColor:locations[i][4], 
     strokeOpacity:0.1, 
     //strokeWeight:1, 
     radius: locations[i][5] // 30 km 
}); 

circle.bindTo('center', marker, 'position'); 

} 

參考文獻: Google Maps JS API v3 - Simple Multiple Marker Example

http://code.google.com/p/gmaps-samples-v3/source/browse/trunk/circle-overlay/circle-overlay.html?r=67

http://plugins.svn.wordpress.org/google-maps-v3-shortcode-multiple-markers/trunk/

回答

1

只要你想創建儘可能多的圈,利用該方法圓的bindTo()

+0

首先,由於@ Dr.Molle – 2013-03-11 04:22:04

0
var infowindow = new google.maps.InfoWindow() 

var marker, i; 
    marker = new google.maps.Marker({ 
    position: new google.maps.LatLng(locations[0][1], locations[0][2]), 
    draggable: true, 
    map: map 
    }); 

for (i = 0; i < locations.length; i++) { 

    var circle = new google.maps.Circle({ 
    map: map, 
    clickable:true, 
    fillColor:locations[i][4], 
    //fillOpacity:0.3, 
    //strokeColor:locations[i][4], 
    strokeOpacity:0.1, 
    //strokeWeight:1, 
    radius: locations[i][5] // 30 km 
    }); 

circle.bindTo('center', marker, 'position'); 

其次結合每個圓圈的position -property標記的center - 屬性,它不容易爲多個圈子疊加添加infowindow。任何想法或提示?例如,http://img443.imageshack.us/img443/8198/overlap.jpg

參考:google maps v3 adding an info window to a circle