如何使用Angular 2的nativescript-google-maps-sdk添加地图标记

时间:2017-05-04 19:05:04

标签: google-maps angular nativescript

我尝试使用NativeScript的this谷歌地图插件。我没有显示地图,但是我没有在文档中看到有关使用Angular 2添加标记的内容。有没有人知道如何使用Angular 2组件向地图添加标记?

1 个答案:

答案 0 :(得分:2)

来自自述文件:https://github.com/dapriett/nativescript-google-maps-sdk/blob/master/README.md

/app/map-example.component.html

<GridLayout>
    <MapView (mapReady)="onMapReady($event)"></MapView>
</GridLayout>

/app/map-example.component.ts

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