Search code examples
javascriptandroidgoogle-mapsnativescript

Google Maps API NativeScript custom marker icon


I try to create a marker with a custom icon with NativeScript and the Google maps API package. I added my icon to the android resources and then built my project a few times.

   var marker = new mapsModule.Marker();
   marker.position = mapsModule.Position.positionFromLatLng(result.latitude, result.longitude);
   marker.title = "Home";
   var icon = new Image();
   icon.imageSource = imageSource.fromResource('bot_marker');
   marker.icon = icon;
   marker.snippet = "This is where I live";
   marker.userData = { index: 1 };
   mapView.addMarker(marker);

Even when I try icon or logo for the ressource it doesn't appear.


Solution

  • Using Angular2

    import { Image } from "ui/image";
    import { ImageSource } from "image-source";
    
        onMapReady(event) {
            console.log("Google map is ready!");
    
            var mapView = event.object;
            var marker = new Marker();
            marker.position = Position.positionFromLatLng(this.state.latitude, this.state.longitude);
    
            let imgSrc = new ImageSource();
            imgSrc.fromResource("pink_pin_dot");
    
            let image = new Image();
            image.imageSource = imgSrc;
    
            marker.icon = image;
            mapView.addMarker(marker);
        }