Rus Mine
Rus Mine

Reputation: 1593

NativeScript Dynamic Map Marker

How to add dynamic markers to my map?
For example ..

<ListView items="{{ myItems }}" itemTap="mapClicked">

When i click my list view item should dynamicaly add a marker to the map. I tried many different ways but with no success.
I tried this repo: https://github.com/dapriett/nativescript-google-maps-sdk
It works fine .. but i can't dynamicaly add markers.

Any help please ?

Upvotes: 0

Views: 1340

Answers (1)

Amjad
Amjad

Reputation: 53

To add markers with nativescript-google-maps-sdk you need to call the native APIs for the respective platform's Google Maps SDK.

Here's an example for Android:

function onMapReady(args) {
  mapView = args.object;

}

function mapClicked(args)
{
   var index = args.index;
   var gMap = mapView.gMap;

   if (mapView.android)
   {
    var latLng = new com.google.android.gms.maps.model.LatLng(12.66, 82.33);

    var markerOptions = new com.google.android.gms.maps.model.MarkerOptions();
    markerOptions.title("Marker " + index);      
    markerOptions.snippet("Marker description");
    markerOptions.position(latLng);

    gMap.addMarker(markerOptions);           

   }
}

Upvotes: 3

Related Questions