Page 3 of 3

Google Maps - get lat/lng on click event

Posted: Mon Mar 24, 2014 5:46 pm
by Professor English

No, there aren't. I simply copied the example above for the events section on the startpage, event, "loads", to run the following javascript
//This adds a new marker where the user has clicked.
google.maps.event.addListener(map, 'click', function(event) {
marker = new google.maps.Marker({position: event.latLng, map: map});
alert("The user picked latlng " + event.latLng + ".");
});

I'm new at this. Any help is greatly appreciated! :)


Google Maps - get lat/lng on click event

Posted: Mon Mar 24, 2014 6:23 pm
by Nikita

What does display this alert? There is specified that this code executes on "click" event, not on "load" event.


Google Maps - get lat/lng on click event

Posted: Mon Mar 24, 2014 7:27 pm
by Professor English

My intention is to allow the user to long click on the map, and store the latLng coordinates into a variable (and then later put them into the system clickboard.)

The alert is just to test and see if the long click returns the latLng.

I may need to start "from zero", from the beginning.

My map component is "googlemap_2" so to trap the click location, in startscreen, under the Events section, for event "loads" I know I need to add a listener, with "GoogleMap.setOnMapLongClickListener(OnMapLongClickListener)" but I'm not sure of the syntax and clauses.

Then, on the "googlemap_2" component Events section, I could add the alert using "onMapLongClick (LatLng point)", but again, I don't have the syntax clear. If you can give me a simple example of the code to use, I can probably work out the rest. Thank you!

Your site and platform are fantastic, by the way.


Google Maps - get lat/lng on click event

Posted: Mon Mar 24, 2014 9:30 pm
by Nikita