首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我是如何用MapView和Angular2在NativeScript上创建指针的?

我是如何用MapView和Angular2在NativeScript上创建指针的?
EN

Stack Overflow用户
提问于 2016-07-28 19:07:03
回答 2查看 1K关注 0票数 0

我的经纬度位置正常,但我需要在那边做一个指针,有可能吗?我正在为Google使用NativeScript、Angular2和NativeScript插件(nativescript-google)

file.ts

代码语言:javascript
复制
import { registerElement } from 'nativescript-angular/element-registry'; 
registerElement("MapView", () => require("nativescript-google-maps-sdk").MapView);

file.xml

代码语言:javascript
复制
<MapView [latitude]="configService.unitPreview.latitude" [longitude]="configService.unitPreview.longitude"
                            zoom="17" bearing="0"
                            tilt="0" (mapReady)="OnMapReady"
                            (markerSelect)="onMarkerSelect"
                            (cameraChanged)="onCameraChanged">
                </MapView>

指针

指针

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-07-29 08:51:54

您可以使用addMarker方法在地图中添加标记。你可以回顾我的例子,这里已经展示了,如何做到这一点。

app,component.html

代码语言:javascript
复制
 <GridLayout>
        <MapView (mapReady)="onMapReady($event)"  ></MapView> 
 </GridLayout>

app.com-ponent.ts

代码语言:javascript
复制
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);
    };
}
票数 1
EN

Stack Overflow用户

发布于 2016-08-11 20:23:20

是否有可能像图片那样显示真实的交通状况?

time.png

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38644811

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档