Page 1 of 3

Adding marker by clicking on map problem

Posted: Thu Jun 06, 2013 12:10 pm
by Dimitris Monastiriotis

hi,
i have a sample app and trying to get it to create a marker when user clicks on the map. The code I use on the load event of the page is:
//make object from the page map
var map = Appery('googlemap_5');

//add a click listener with function to place a marker at the event's latlong
google.maps.event.addListener(map, 'click', function(e) {
placeMarker(e.latLng, map);
map.refresh();
alert('1');
});

//code to actually place the marker
function placeMarker(position, map) {
var marker = new google.maps.Marker({
position: position,
map: map
});
map.options.mapElement.gmap('addMarker',marker);
map.panTo(position);
map.options.mapElement.gmap("refresh");
}

however when i test it, it does nothing when I click on the map (do not know if it is important but the cursor's icon when i am over the map is the pan hand)

I would appreciate any suggestions, comments or help

rgrds


Adding marker by clicking on map problem

Posted: Thu Jun 06, 2013 12:38 pm
by Maryna Brodina

Hello! Are there any JS errors in console?


Adding marker by clicking on map problem

Posted: Thu Jun 06, 2013 12:45 pm
by Dimitris Monastiriotis

This is the only output in the console.

Cannot refresh, map is not initialized! appery.js:2067

but this is a warning not an error. The problem is that when I click on the map the code in google.maps.event.addListener(map, 'click', function(e) {
placeMarker(e.latLng, map);
map.refresh();
alert('1');
});

is not executed to add a marker


Adding marker by clicking on map problem

Posted: Thu Jun 06, 2013 3:30 pm
by Dimitris Monastiriotis

google.maps.event.addListener(Appery('googlemap_5'),'click',function(event) {
localStorage.setItem('myPos', event.latLng);
placeMarker(event.latLng,map);

});

Just to offer another piece of info, according to my debugging it looks like it does not register the event


Adding marker by clicking on map problem

Posted: Thu Jun 06, 2013 4:10 pm
by Dimitris Monastiriotis

please check my follow up posts


Adding marker by clicking on map problem

Posted: Thu Jun 06, 2013 4:20 pm
by Kateryna Grynko

Hello Dimitris,

Working on it.


Adding marker by clicking on map problem

Posted: Thu Jun 06, 2013 4:30 pm
by Dimitris Monastiriotis

oh ok thanks, i read quite a bit on the forum and the various answers and it should really work, the same I tried in http://www.w3schools.com/googleAPI/tr... with the appropriate changes and works fine, so i am totaly at a loss why it doesn't work inside appery.

thanks for the effort


Adding marker by clicking on map problem

Posted: Thu Jun 06, 2013 5:13 pm
by Kateryna Grynko

Run the following code:
codegoogle.maps.event.addListener(Appery('googlemap_5').gmap, 'click', function(event) {
localStorage.setItem('myPos', event.latLng);
placeMarker(event.latLng,map);
});/code
Appery('googlemap_5').gmap contains data that function tries to get from Google code.


Adding marker by clicking on map problem

Posted: Thu Jun 06, 2013 6:12 pm
by Dimitris Monastiriotis

thanks for that , it worked when I put it in the click event of the map object. that means that the user would have to click once for the listener to be set and then to create the marker.
Is there an event I could place it to run before the user starts interacting with the map?

thanks again


Adding marker by clicking on map problem

Posted: Fri Jun 07, 2013 7:47 am
by Maryna Brodina

Hello! Could you explain us in more details what are you going to do on event?