gpt4 book ai didi

typescript - 使用 Angular 2 连接 Google Maps Nativescript 插件

转载 作者:搜寻专家 更新时间:2023-10-30 21:24:44 24 4
gpt4 key购买 nike

我正在尝试将适用于 Nativescript ( https://github.com/dapriett/nativescript-google-maps-sdk ) 的 Google map 插件与 Angular 2 和 {N}-Angular 路由器一起使用。我让它在 Nativescript 中工作,但是一旦我添加了 Angular 2 和路由器,我就无法让 map 显示在 UI 中。

<Page>标签没有进入 Angular2 {N} 组件模板,我不能使用 xmlns:maps="nativescript-google-maps-sdk" <Page> 上的命名空间实例化 <maps:mapView>

{N} 组件基础页面提供了一些指导,但它无法按照我尝试过的方式工作:https://docs.nativescript.org/ui/ui-with-xml#user-interface-components

关于执行此操作的正确方法有什么想法吗?

应用程序组件.ts

import {Component} from "angular2/core";
import {RouteConfig} from "angular2/router";
import {NS_ROUTER_DIRECTIVES, NS_ROUTER_PROVIDERS} from "nativescript-angular/router";
import {HomeComponent} from "./pages/home/home.component";

@Component({
selector: "app-main",
directives: [NS_ROUTER_DIRECTIVES],
providers: [NS_ROUTER_PROVIDERS],
template: "<page-router-outlet ></page-router-outlet>"
})
@RouteConfig([
{ path: "/home", component: HomeComponent, as: "Home", useAsDefault: true },
])
export class AppComponent {
}

主页.html

<stack-layout orientation="vertical">
<label [text]="message"></label>
<mapView [latitude]="latitude" [longitude]="longitude"
[zoom]="zoom" [bearing]="bearing"
[tilt]="tilt" (mapReady)="OnMapReady"
(markerSelect)="onMarkerSelect"
(cameraChanged)="onCameraChanged">
</mapView>
</stack-layout>

home.component.ts

import {Component} from "angular2/core";
var geolocation = require("nativescript-geolocation");
var mapsModule = require("nativescript-google-maps-sdk");
exports.mapView = mapsModule.MapView; //Doesn't work
exports.mapView = new mapsModule.MapView(); //Doesn't work
exports.mapView = mapsModule; //Doesn't work

@Component({
selector: "home",
templateUrl: "pages/home/home.html",
})
export class HomeComponent {
public message:string = "Message set.";
public latitude:number = 30.0;
public longitude:number = -100.0;
public zoom:number = 10;
public bearing:number = 0;
public tilt:number = 0;

constructor() {
this.message = "Home constructed.";
}
OnMapReady(args) { }
onMarkerSelect(args) { }
onCameraChanged(args) { }
}

最佳答案

您需要使用 element-registry API 注册 mapView 标签名称,例如:

https://github.com/NativeScript/nativescript-angular/blob/master/src/nativescript-angular/element-registry.ts#L70-L105

该 API 尚未记录,但我们应该在未来几周内解决该问题。

关于typescript - 使用 Angular 2 连接 Google Maps Nativescript 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36443476/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com