我尝试使用NativeScript的this谷歌地图插件。我没有显示地图,但是我没有在文档中看到有关使用Angular 2添加标记的内容。有没有人知道如何使用Angular 2组件向地图添加标记?
答案 0 :(得分:2)
来自自述文件:https://github.com/dapriett/nativescript-google-maps-sdk/blob/master/README.md
<GridLayout>
<MapView (mapReady)="onMapReady($event)"></MapView>
</GridLayout>
import {Component, ElementRef, ViewChild} from '@angular/core';
import { MapView, Position, Marker } from 'nativescript-google-maps-sdk';
@Component({
selector: 'map-example-component',
templateUrl: 'map-example.component.html'
})
export class MapExampleComponent {
private mapView: MapView;
//Map events
private onMapReady(args): void {
this.mapView = args.object;
this.addMarker();
}
private addMarker(): void {
console.log("Setting a marker...");
var marker = new Marker();
marker.position = Position.positionFromLatLng(-33.86, 151.20);
marker.title = "Sydney";
marker.snippet = "Australia";
marker.userData = { index : 1};
this.mapView.addMarker(marker);
}
}