Cordova-plugin-googlemaps: marker pass parameter

Created on 7 Jun 2019  路  12Comments  路  Source: mapsplugin/cordova-plugin-googlemaps

i am using the plugin in ionic 3 app
and addmarker ( for multi marker ) for places
i need to make id to callback when click the marker

how can i do this , is this plugin do this

please help

All 12 comments

it just give
position
icon
title

need to put my data

Just add your data, then use get() method to obtain it.

can u give me example please

marker = this.map.addMarkerSync({
  position: ....,
  title: ....,
  myData: "hello world"
});

console.log(marker.get("myData"));

i did that but not work for my

marker = this.map.addMarker({
position : ...,
icon : .....,
placeid : ...
}):

marker.on(GoogleMapsEvent.MARKER_CLICK,).subscribe(()=>{
var theplaceid = marker.get('placeid'):
alert(thepaceid):
});

this is my code put not working and not get the alert
i use ( cordova-plugin-googlemaps 2.6.2 )

please help

Please share your project files on GitHub repository.

@wf9a5m75 did u see my code

what is wrong in it

I'm not your teacher or friend. Please do not still my private time. Please share your project files to reproduce your issue, otherwise close the issue

@wearta

This is how you should be passing parameters and getting the parameters back when the marker is tapped on:

marker = map.addMarker({
          position: {lat: XXXXXXX, lng: XXXXXXXX},
          title: "Some title goes here",
          snippet: "This plugin is awesome!",
          _id: 'someID',
          animation: plugin.google.maps.Animation.BOUNCE      
        });


  marker.on(plugin.google.maps.event.MARKER_CLICK, function() {
    alert(marker.get("_id"));
  });

However, this method seems to only work for 1 marker!

So, if you have multiple makers on the map, and when you click/tap on one of the markers, the marker.get("_id") only shows the _id of the last marker that was added to the map!

maybe @wf9a5m75 can explain this better?

@wearta

Done.

here is what you need to do:

marker = map.addMarker({
          position: {lat: XXXXX, lng: XXXXXX},
          title: "Some title goes here",
          snippet: "This plugin is awesome!",
          icon: 'marker.png',
           _id: 'myID',
          animation: plugin.google.maps.Animation.BOUNCE
}, function(marker) {
   marker.on(plugin.google.maps.event.MARKER_CLICK, function() {
      alert(marker.get("_id")); 
   });

});

This works with multiple Markers too.

IMPORTANT: The word 'id' is reserved by this plugin so you cannot use that. instead you need to use something else like _id or marker_id etc etc...

Happy coding. :)

IMPORTANT: The word 'id' is reserved by this plugin is old.

In the latest version, '_id' is reserved word. 'id' is not reserved word.

@wf9a5m75 thank you for the update. I take a note of that as i will be updating to the latest version soon.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

splitice picture splitice  路  5Comments

Tong2203 picture Tong2203  路  5Comments

bigbossmaher picture bigbossmaher  路  3Comments

rosnaib11 picture rosnaib11  路  5Comments

lakano picture lakano  路  4Comments