Page 1 of 1

Get click event Google map

Posted: Sat Jul 12, 2014 2:23 am
by Beej

How do I get a click event to fire on a Google map? The click event for the control fires no problem, but not the map itself, so its event can be used.

Perused this page and nothing helped:
https://getsatisfaction.com/apperyio/...

This should be an easy task, but doesn't work (no error messages):
premap = new google.maps.Map(document.getElementById('pageName_map'));
google.maps.event.addListener(map, 'click', function(event) {
console.log('click');
ClearMarkers();
AddMarker(map, event.latLng);
});/pre


Get click event Google map

Posted: Sat Jul 12, 2014 2:49 am
by Alena Prykhodko

Hello,

Could you please specify what are you trying to do?
Do you want to add come action when you click on map?


Get click event Google map

Posted: Sat Jul 12, 2014 3:18 am
by Beej

Like the code sample suggests, I want to allow a user to choose a location on the map, when they click (or tap) on it.

I don't know how to access the proper map object in Appery....


Get click event Google map

Posted: Sat Jul 12, 2014 5:03 am
by Beej

I had to do one of these to wait for the gmap property of the map object:
prevar max = 10;
var cnt = 0;
function Wait() {
if (typeof Appery('map_begin')&#46;gmap == 'undefined' && cnt < max) {
cnt++;
setTimeout(Wait, 1000);
return;
}
gMap = Appery('map_begin')&#46;gmap;
google&#46;maps&#46;event&#46;addListener(gMap, 'click', function(event) {
console&#46;log('google click');
ClearMarkers();
AddMarker(gMap, event&#46;latLng);
});
}
Wait();/pre
This is in the page load event. Is there a more elegant way to do this?

Probably just create my own map object altogether...?


Get click event Google map

Posted: Sun Jul 13, 2014 11:38 pm
by Yurii Orishchuk

Hi Beej,

Yes you can access this object before google map component will initialized.

Please use following code to get this object.

pre

Code: Select all

 &#47;&#47;Note: you should to replace "google_map" with your map component name&#46; 
 var mapName = "google_map"; 

 var map = Appery(mapName)&#46;options&#46;mapElement&#46;gmap('get', 'map'); 

 &#47;&#47;Now you can use map object&#46; 

/pre

Regards.


Get click event Google map

Posted: Mon Jul 14, 2014 1:36 am
by Beej

Exactly what I needed. Thanks!