Add marker from custom.js
-
Hello,
I have a little trouble. I’ve read whole plugin but cannot find function how to add marker. I go crazy but no matter what I tried it acts weird.
I have a global map and button with eventlistner activating geolocation.
everything works, but now I want to create marker.
I googled it millions of times, and did everything but nothing works.
Once I managed to get it working, but it was deleting other markers. like when click to show other categories they are displayed in sidebar (nearby_posts) but markers are not on a map/* * Center maps on user location when available. */ GeoMashup.addAction( 'loadedMap', function( properties, map ) { var initialLocation; var siberia = new google.maps.LatLng(60, 105); var newyork = new google.maps.LatLng(40.69847032728747, -73.9514422416687); var browserSupportFlag = new Boolean(); var marker; if ( 'global' != properties.map_content ) { // Don'ts center non-global maps on user return; } window.parent.document.getElementById("paybox").addEventListener("click", function(){ // Try W3C Geolocation (Preferred) if(navigator.geolocation) { browserSupportFlag = true; navigator.geolocation.getCurrentPosition(function(position) { // uncheck other marker categories var check = window.parent.document.getElementById("gm-category-check-all"); //double click check_all if any selected but not all if ( $( check ).is( ':checked' ) ) { $(check).click(); } else { $(check).click(); $(check).click(); } var initialLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude); }, function() { handleNoGeolocation(browserSupportFlag); }); // Try Google Gears Geolocation } else if (google.gears) { browserSupportFlag = true; var geo = google.gears.factory.create('beta.geolocation'); geo.getCurrentPosition(function(position) { var myLatLng = new google.maps.LatLng(-25.363882, 131.044922); map.setCenter( myLatLng ); }, function() { handleNoGeoLocation(browserSupportFlag); }); // Browser doesn't support Geolocation } else { browserSupportFlag = false; handleNoGeolocation(browserSupportFlag); } function handleNoGeolocation(errorFlag) { if (errorFlag == true) { initialLocation = newyork; } else { initialLocation = siberia; } map.setCenter(initialLocation); } },false); } );how to add marker without destroying other markers?
and yes, it works if I do maps.setZoom but not when I do maps.SetCenter
in my google maps v3 but v2 works perfect
The topic ‘Add marker from custom.js’ is closed to new replies.