Created
July 26, 2016 15:07
-
-
Save Fitoussi/4b62a5bf43533093d78cd7bed0777ddc to your computer and use it in GitHub Desktop.
Move map marker with a click on the map.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function gfgeo_move_map_marker_onclick() { | |
?> | |
<script> | |
jQuery( document ).on( 'gfgeo_render_map', function( event, GF_Geo, map_data ) { | |
GF_Geo.map_single_click = false; | |
google.maps.event.addListener( GF_Geo.maps[map_data.map_id].map, 'click', function( event) { | |
GF_Geo.map_single_click = true; | |
setTimeout( function() { | |
if ( GF_Geo.map_single_click ) { | |
GF_Geo.maps[map_data.map_id].marker.setPosition( event.latLng ); | |
// set the global Geocoder ID | |
GF_Geo.geocoder_id = map_data.geocoder_id; | |
// geocode coords to get address fields | |
GF_Geo.geocoder( 'map', [ event.latLng.lat(), event.latLng.lng() ], GF_Geo.map_geocoder_success, false ); | |
} | |
}, 200); | |
}); | |
google.maps.event.addListener( GF_Geo.maps[map_data.map_id].map, 'dblclick', function( event ) { | |
GF_Geo.map_single_click = false; | |
}); | |
}); | |
</script> | |
<?php | |
} | |
add_action( 'wp_footer', 'gfgeo_move_map_marker_onclick' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment