2016-11-26 35 views
0

我嘗試使用NativeScript和Google maps API包創建帶有自定義圖標的標記。我將我的圖標添加到了android資源中,併爲我的項目創建了幾次。Google Maps API NativeScript自定義標記圖標

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); 

即使當我嘗試「圖標」或「徽標」的資源它不會出現。

回答

3

使用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); 
    }