• Resolved b a

    (@mpa4hu)


    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

    http://wordpress.org/extend/plugins/geo-mashup/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter b a

    (@mpa4hu)

    Or blue dot or anything which can be easier to implement and seasy to recognize where you are now

    Plugin Author Dylan Kuhn

    (@cyberhobo)

    I haven’t found a geolocation API implementation I would call easy yet. Probably you need to account for the change from the google maps v2 API to the Mapstraction API in your custom javascript:

    https://code.google.com/p/wordpress-geo-mashup/wiki/Documentation#JavaScript_and_map_providers

    I think Geo Mashup is working as documented there.

    Thread Starter b a

    (@mpa4hu)

    Okay so I’m using Google V3, so I renamed my custom file to
    custom-googlev3.js and changed variable map to mxn.

    Now in my geopointer I should do something like this:

    var point = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
    var google_map = mxn.getMap();
    mxn.Marker(point);

    it’s still not working.

    What there can be hard? you have everything already written, I can alert geolocated Lat and Long. I just need to place marker on that point without destroying other markers.

    Thread Starter b a

    (@mpa4hu)

    If I could manage mxn inside my custom js It has everything I want next.

    Thread Starter b a

    (@mpa4hu)

    Thanks mxn worked perfect!
    Here is a code for half implemented geolocation with marker added if anyone would need some code

    /*
    * Center maps on user location when available.
    */
    // An Example Google V3 customization
    
    GeoMashup.addAction( 'loadedMap', function( properties, mxn ) {
    	var pointerz;
    	var geomarker;
    	var siberia = new google.maps.LatLng(60, 105);
    	var newyork = new google.maps.LatLng(40.69847032728747, -73.9514422416687);
    	var browserSupportFlag =  new Boolean();
    
    	if ( 'global' != properties.map_content ) {
    		// Don'ts center non-global maps on user
    		return;
    	}
    	var payboxcount = 1;
    	var paybox = window.parent.document.getElementById("paybox");
    
        paybox.addEventListener("click", function(){
        	payboxcount++;
        	$(paybox).toggleClass('btn-new-maps-selected');
        		// 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();
    			}
    		if ( payboxcount % 2 === 0 ) {
    			// Try W3C Geolocation (Preferred)
    			if(navigator.geolocation) {
    				browserSupportFlag = true;
    				navigator.geolocation.getCurrentPosition(function(position) {
    
    				var pointerz = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
    				var google_map = mxn.getMap();
    				geomarker = new google.maps.Marker({
    					    position: pointerz,
    					    map: google_map,
    					    title:"პირვეტ ს მარსა!"
    					});
    
    					GeoMashup.showCategory(45);
    					// To add the marker to the map, call setMap();
    					geomarker.setMap(google_map);
    					geomarker.setAnimation(google.maps.Animation.BOUNCE);
    					google_map.setZoom(16)
    					google_map.setCenter( pointerz );
    				}, 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 pointerz = new google.maps.LatLng(-25.363882, 131.044922);
    
    				var google_map = mxn.getMap();
    				geomarker = new google.maps.Marker({
    					    position: pointerz,
    					    map: google_map,
    					    title:"Hello World!"
    					});
    
    					GeoMashup.showCategory(45);
    					// To add the marker to the map, call setMap();
    					geomarker.setMap(google_map);
    					geomarker.setAnimation(google.maps.Animation.BOUNCE);
    					google_map.setZoom(16)
    					google_map.setCenter( pointerz );
    				}, 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);
    			}
    		} else { // DESTROY EVERYTHING I CREATED
    			GeoMashup.hideCategory(45);
    			geomarker.setMap(null);
    
    		}
    
    	},false);
    
    } );
    Plugin Author Dylan Kuhn

    (@cyberhobo)

    Glad you got it worked out, thanks for sharing!

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Add marker from custom.js’ is closed to new replies.