Forge Component
(16)
Published on 2018-10-11 by Labs
16 votes
Published on 2018-10-11 by Labs

I'm using the Google Maps Mobile plugin, and i need when a tap(click) in a random road/place, get the coordinates from that click, then some pop-up shows with some options, like put a marker on that place, but i cant find how do this.

I've already tried create this javascript and execute on many places their i can call, but doesnt work at all. 


This i load on Container ClickEvent, that have around the maps plugin, but i've tried on many places. I know i have to create an Event Listener, but first i have to reference the object that i want to do this.

Hi,

You can add one more click event listener to map object like below.

map.addListener('click', function(e) {
    //e.latLng property denoting the clicked location on the map;
});

You might need to combine example from

https://developers.google.com/maps/documentation/javascript/examples/event-properties (for Information window and how to place it)

https://developers.google.com/maps/documentation/javascript/events#EventArguments (for event and getting the lat and long)

I hope this helps.

Thanks.

Prasad, thanks for help me! 

I looked at this examples and tried to this:

First i create this action with the javascript with the Listener, and associated on MapInitialized Event on the Maps plugin, passing to the action the Id returned on this same Event.


In the Action "MapaIni", i have this:


On Google Chrome Console, whats happened:


Only this show on Console, and when i click, nothing either.

In Outsystems, he execute the action:


Other thing that it's strange, the Id in this case is "b3-MapContainer", just on the Event Id MapInitialized, others if a get the Map Widget Idm it is the name i gave him "centralmap".


I dont know what to do anymore :/


Solution

Hi Deivd,

By looking at your code, it seems that you're creating a new map and adding a listener to it, instead of adding a listener to the existing one.

On the event of map initialized, you probably want something like this (it's just changing the event of 'dragend' to 'click'):


First you need to get the map object, and then add the listener to that map. Having that its just setting the callbacks as your actions and you'll need to append a new marker to your existing marker list.


Hope it helps

Solution

Thank you so much Henrique Batista, it was more simple that i think!

Now i'm gonna make some action to add a new Mark on the marklist.