Beej
Posts: 0
Joined: Tue Jul 01, 2014 1:56 am

Get click event Google map

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

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

Get click event Google map

Hello,

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

Beej
Posts: 0
Joined: Tue Jul 01, 2014 1:56 am

Get click event Google map

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....

Beej
Posts: 0
Joined: Tue Jul 01, 2014 1:56 am

Get click event Google map

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...?

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Get click event Google map

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.

Beej
Posts: 0
Joined: Tue Jul 01, 2014 1:56 am

Get click event Google map

Exactly what I needed. Thanks!

Return to “Issues”