Google Maps API NativeScript自定义标记图标
问题描述:
我尝试使用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);
即使当我尝试“图标”或“徽标”的资源它不会出现。
答
使用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);
}