6

क्लस्टर करते समय ऑब्जेक्ट 'getPosition' नहीं है I Google Maps Utility Library v3 का उपयोग करके Google मानचित्र पर क्लस्टरिंग मार्करों का मूल कार्यान्वयन करने का प्रयास कर रहा हूं।ऑब्जेक्ट में Google Map markers (api v3)

जब मैं इस हालांकि चलाने के लिए, मैं Chrome डेवलपर टूल कंसोल पर कोई त्रुटि मिलती है: http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerclusterer/src/markerclusterer.js:

Uncaught TypeError: Object #<Object> has no method 'getPosition' 

यह 649 यहाँ उपयोगिता पुस्तकालय लिपि में लाइन से संबंधित है। निम्नलिखित में से कौन समारोह है:

/** 
* Determins if a marker is contained in a bounds. 
* 
* @param {google.maps.Marker} marker The marker to check. 
* @param {google.maps.LatLngBounds} bounds The bounds to check against. 
* @return {boolean} True if the marker is in the bounds. 
* @private 
*/ 
MarkerClusterer.prototype.isMarkerInBounds_ = function(marker, bounds) { 
    return bounds.contains(marker.getPosition()); 
}; 

कोड मैं उपयोग कर रहा हूँ यथोचित मानक गूगल के नक्शे सामान है, मुख्य कार्य है जिसके लिए है:

function initialize(items,loop,zoom) { 
    geocoder = new google.maps.Geocoder(); 
    if (items.length > 0) { 
    var latlng = new google.maps.LatLng(items[0].Lat, items[0].Lng); 
    var myOptions = { 
     zoom: zoom, 
     center: latlng, 
     //mapTypeControl: false, 
     streetViewControl: false, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 

    map = new google.maps.Map(document.getElementById("map"), myOptions); 
    map.setOptions({styles: stylez}); 

    for (var i = 0; i < items.length; i++) { 
     var marker = new google.maps.Marker({ 
     position: new google.maps.LatLng(items[i].Lat, items[i].Lng), 
     title: items[i].Title, 
     icon: _iconCenter, 
     shadow: shadow, 
     infocontent: items[i].Description 
     }); 
     marker.setMap(map); 
     markersArray.push(marker); 
    } 
    var markerCluster = new MarkerClusterer(map, items); 
    google.maps.event.addListener(map, "tilesloaded", function() { 
     if(loop == true){ 
     SetLoop(); 
     } 
    }); 
    } 
} 

मैं erroring समारोह पता लगाया गया है जहाँ तक जैसा कि मैं समझता हूं और इसे सीमा के निर्धारण के लिए मानचित्र के किनारों के लिए निर्देशांक प्राप्त करना चाहिए, जो कि मानक व्यवहार होना चाहिए, लेकिन स्पष्ट रूप से कुछ सही नहीं है।

मुझे आश्चर्य हुआ कि क्या कोई इस पर कोई प्रकाश डाल सकता है?

किसी भी संकेत दिए गए लोगों के लिए धन्यवाद ...

उत्तर

4

मुद्दा निकला तथ्य यह है कि मैं markerclusterer स्क्रिप्ट घोषित किया गया था गूगल के नक्शे से पहले स्क्रिप्ट किया जाना है। नक्शा स्क्रिप्ट को कॉल करने से पहले इसे हल किया गया ... अब स्पष्ट!

+3

किसी के लिए आपकी मदद करने के लिए आपकी पोस्ट में पर्याप्त जानकारी नहीं थी। – geocodezip

+2

हिंडसाइट में आप सही हैं, लेकिन मुझे नहीं पता था कि यह मुद्दा था - मैंने सोचा था कि यह मुद्दा मेरे कार्य के साथ या क्लस्टरर लाइब्रेरी के साथ था। – Dan

+0

मुझे संदेह है कि स्रोत ऑर्डर समस्या थी, मुझे एपीआई स्क्रिप्ट से पहले मेरी मार्करक्लस्टर.जेएस फ़ाइल शामिल है, जैसा कि यह [डॉक्स] में कहता है (https://developers.google.com/maps/documentation/javascript/marker -clustering) और सब कुछ ठीक काम कर रहा है। शायद एक अलग मुद्दा था। – stephenmurdoch

4

MarkerClusterer मार्करों की एक सरणी की उम्मीद है। आप एक बनाते हैं, लेकिन आइटम सरणी को इसके कन्स्ट्रक्टर में पास करते हैं। परिवर्तित करें:

var markerCluster = new MarkerClusterer(map, items); 

रहे हैं:

var markerCluster = new MarkerClusterer(map, markersArray); 
+0

धन्यवाद - इससे किसी समस्या का कारण हो सकता है, इसलिए इसे इंगित करने के लिए धन्यवाद। इसे बदलने से मूल त्रुटि प्रभावित नहीं हुई, हालांकि फ़ंक्शन में 'markersArray' का उपयोग करते समय भी यह हुआ। मुझे वास्तव में मूल मुद्दे का समाधान मिला है और मूल पोस्ट का उत्तर जोड़ा गया है। आपकी मदद के लिए फिर से धन्यवाद - यह शायद मेरा अगला मुद्दा होगा;) – Dan

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