Hank Joreid
Posts: 0
Joined: Mon Apr 20, 2015 1:00 pm

Change Map Marker location on click

Hi, i have a map in my app with a marker thats dragable.
But i need the user just to "click" at the location on the map where the marker shold be changed to.

se my code:
code
var oMyMap ;
var nTimerHandle;
var oGlobalMarker ;
var bMarkerDropped = false;

function fInitMarker(){
if (bMarkerDropped) { return ;}
oMyMap = Appery("mapMyMap").options.mapElement.gmap('get', 'map');
nTimerHandle = setInterval(function(){ fmyTimer(); }, 500);
return;
}

function fmyTimer() {
console.log('waiting for Map to Initialize');
if (oMyMap && oMyMap.center.toString() !== "(0, 0)" ){
fmyStopFunction();
// then initialize other things - set other properties about the map and the marker
fmyMarkerInit();
bMarkerDropped = true ;
}
return ;
}

function fmyStopFunction() {
clearInterval( nTimerHandle );
}

function fmyMarkerInit() {
// create a marker and make it draggable... and add a listener event for when it's dragged...
var oposition = new google.maps.LatLng( localStorage.getItem('s_lat'), localStorage.getItem('s_long') );
var oMarker = new google.maps.Marker({
position: oposition, // a position object defined previiously
map: oMyMap, // your map object
draggable: true, // set the draggable property to true
title: "Drag", // title for the marker
animation: google.maps.Animation.DROP,// remove if you want
// icon: 'http://maps.google.com/mapfiles/kml/pal2/icon13.png' // not required
});
google.maps.event.addListener( oMarker , 'dragend', function( ) {
console.log('moving marker with title: ' + oMarker.getTitle() );
fmovemarker( oMarker );
} );
oGlobalMarker = oMarker;
oMyMap.panTo( oposition );
}

function fRemoveMarker(){
oGlobalMarker.setMap( null );
oGlobalMarker = null ;
return ;
}

function fmovemarker( omarker )
{
var stitle = omarker.getTitle();
var oposition = omarker.getPosition();
var nLat = oposition.lat();
var nLng = oposition.lng();
//alert('New Position is: ' + oposition.toString() );
// see if the position is within the course bounds....
console.log('moved marker ...:');
localStorage.setItem('n_long', oposition.lng() );
localStorage.setItem('n_lat', oposition.lat() );
// service_updatemarker.execute({});
return ;
}
/code
what to change to get the marker "Clickable"

Pavel Zarudniy
Posts: 0
Joined: Mon Jul 06, 2015 8:56 am

Change Map Marker location on click

Hi Hank,
Please look at this Google Map API documentation -
https://developers.google.com/maps/do...

Return to “Issues”