2011-10-25 9 views
6

मैं गूगल मैप्स (एपीआई) के लिए नया हूँ और मैं निम्नलिखित परिणाम प्राप्त करने की आवश्यकता:, मुझे पता है यह नक्शे पर और जगह मार्करों रेंडर करने के लिए कैसेGoogle मानचित्र में पथ के साथ सभी मार्करों में कैसे शामिल हों?

paths

फिलहाल (देशांतर के आधार पर और अक्षांश)।

var map; 

map = new google.maps.Map(document.getElementById('map_canvas'), { 
    zoom: 7, 
    center: new google.maps.LatLng(response[0].latitude, response[0].longitude), 
    mapTypeId: google.maps.MapTypeId.ROADMAP 
}); 

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

    new google.maps.Marker({ 
     'map' : map, 
     'position' : new google.maps.LatLng(response[i].latitude, response[i].longitude), 
     'title' : response[i].address 
    }); 

} 

चर response संरचना की तरह है:

[ 
Object 
address: "Krišjāņa Barona iela 25, Riga, LV-1011, Latvia" 
latitude: "24.1245290" 
longitude: "56.9528510" 
__proto__: Object 
, 
Object 
address: "Rīgas iela 1, Tukums, Tukuma novads, LV-3101, Latvia" 
latitude: "23.1630590" 
longitude: "56.9663880" 
__proto__: Object 
] 

मार्कर का एक बहुत वहाँ हो सकता है। मैं पूर्वावलोकन छवि में पथों के साथ मार्करों में शामिल होने का एक तरीका ढूंढ रहा हूं।

मुझे नहीं पता कि मुझे क्या खोजना चाहिए और मुझे इसमें आपकी मदद की ज़रूरत है। एक सलाह में धन्यवाद!

उत्तर

9

एक उदाहरण Google's tutorial से:

var flightPlanCoordinates = [ 
    new google.maps.LatLng(37.772323, -122.214897), 
    new google.maps.LatLng(21.291982, -157.821856), 
    new google.maps.LatLng(-18.142599, 178.431), 
    new google.maps.LatLng(-27.46758, 153.027892) 
    ]; 
    var flightPath = new google.maps.Polyline({ 
    path: flightPlanCoordinates, 
    strokeColor: "#FF0000", 
    strokeOpacity: 1.0, 
    strokeWeight: 2 
    }); 

इसके अलावा, the reference entry for Polylines देखते हैं।

आप नहीं जानते, तो LatLng वस्तुओं की एक सरणी के जवाब वस्तु मैप करने के लिए कैसे, यहाँ एक उदाहरण है:

var flightPath = responseArray.map(function (item) { 
    return new google.maps.LatLng(item.latitude, item.longitude); 
}); 
+0

मैं था मुसीबत अभी भी अपने परिशिष्ट पर स्पष्ट नहीं well-- के रूप में इस पर विशेष खोजने प्रतिक्रिया के लिए। क्या आप विस्तार कर सकते हैं? –

+0

अंत में आपको यह जोड़ना चाहिए, flightPath.setMap (मानचित्र); –

संबंधित मुद्दे