2016-07-28 39 views
0

我的經度和緯度位置正在工作,但我需要在那裏做一個指針,有可能嗎?我使用NativeScript,Angular2和NativeScript插件谷歌地圖SDK(nativescript - 谷歌-SDK)我如何使用NativeScript和Angular2製作MapView指針?

file.ts

import { registerElement } from 'nativescript-angular/element-registry'; 
registerElement("MapView",() => require("nativescript-google-maps-sdk").MapView); 

file.xml

<MapView [latitude]="configService.unitPreview.latitude" [longitude]="configService.unitPreview.longitude" 
          zoom="17" bearing="0" 
          tilt="0" (mapReady)="OnMapReady" 
          (markerSelect)="onMarkerSelect" 
          (cameraChanged)="onCameraChanged"> 
       </MapView> 

map_without_pointer

map_with_pointer

回答

0

您可以使用addMarker方法在地圖中添加標記。您可以在下面查看我的示例,其中顯示瞭如何執行此操作。

app,component.html

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

app.com-ponent.ts

import {Component, ElementRef, ViewChild} from '@angular/core'; 
var mapsModule = require("nativescript-google-maps-sdk"); 


@Component({ 
    selector: "my-app", 
    templateUrl: "app.component.html", 
}) 
export class AppComponent { 

    @ViewChild("MapView") mapView: ElementRef; 
    constructor(){ 

    } 
    //Map events 
    onMapReady = (event) => { 
     console.log("Map Ready"); 
     var map =event.object; 
     var marker = new mapsModule.Marker(); 
     marker.position = mapsModule.Position.positionFromLatLng(48.87, 2.35); 
     marker.title = "Sydney"; 
     marker.snippet = "Australia"; 
     marker.userData = { index : 1}; 
     map.addMarker(marker); 
    }; 
} 
+0

謝謝尼古拉。我也改變了標記的圖標... 'var image = new ImageModule.Image(); var imageSource = imageSourceModule.fromResource(「icon」); image.imageSource = imageSource; marker.icon = image;' – Fernanda