Google maps Can';t将谷歌地图集成到我的爱奥尼亚2应用程序中
我正试图把谷歌地图放到我的应用程序中 添加了GMaps插件Google maps Can';t将谷歌地图集成到我的爱奥尼亚2应用程序中,google-maps,ionic-framework,ionic2,Google Maps,Ionic Framework,Ionic2,我正试图把谷歌地图放到我的应用程序中 添加了GMaps插件 ionic plugin add cordova-plugin-googlemaps --variable API_KEY_FOR_ANDROID="my android api" --variable API_KEY_FOR_IOS="my ios api" 添加了必要的依赖项 npm install 但是,当我尝试运行该应用程序时,会出现此运行时错误 以下是typescript代码: import {Component} fro
ionic plugin add cordova-plugin-googlemaps --variable API_KEY_FOR_ANDROID="my android api" --variable API_KEY_FOR_IOS="my ios api"
添加了必要的依赖项
npm install
但是,当我尝试运行该应用程序时,会出现此运行时错误
以下是typescript代码:
import {Component} from "@angular/core";
import {
GoogleMap,
GoogleMapsEvent,
GoogleMapsLatLng,
GoogleMapsMarker,
Geolocation
} from 'ionic-native';
@Component({
selector: 'page-about',
templateUrl: 'about.html'
})
export class AboutPage {
private _latitude: number;
private _longitude: number;
constructor() {}
ngAfterViewInit() {
let map = new GoogleMap(document.getElementById('map'));
// when the map is ready
map.one(GoogleMapsEvent.MAP_READY).then(() => {
Geolocation.getCurrentPosition().then(pos => {
this._latitude = pos.coords.latitude;
this._longitude = pos.coords.longitude;
// move the camera
map.moveCamera({
target: new GoogleMapsLatLng(this._latitude, this._longitude),
zoom: 18,
tilt: 30
}).then(() => {
// add a marker
map.addMarker({
position: new GoogleMapsLatLng(this._latitude, this._longitude),
title: 'You are here!'
})
// show marker info
.then((marker: GoogleMapsMarker) => {
marker.showInfoWindow();
// listen to all available events
map.on(GoogleMapsEvent.MAP_CLICK).subscribe(
() => {
alert('MAP_CLICK');
});
map.on(GoogleMapsEvent.MAP_LONG_CLICK).subscribe(
() => {
alert('MAP_LONG_CLICK');
});
map.on(GoogleMapsEvent.MY_LOCATION_CHANGE).subscribe(
() => {
alert('MY_LOCATION_CHANGE');
});
map.on(GoogleMapsEvent.MY_LOCATION_BUTTON_CLICK).subscribe(
() => {
alert('MY_LOCATION_BUTTON_CLICK');
});
map.on(GoogleMapsEvent.INDOOR_BUILDING_FOCUSED).subscribe(
() => {
alert('INDOOR_BUILDING_FOCUSED');
});
map.on(GoogleMapsEvent.INDOOR_LEVEL_ACTIVATED).subscribe(
() => {
alert('INDOOR_LEVEL_ACTIVATED');
});
map.on(GoogleMapsEvent.CAMERA_CHANGE).subscribe(
() => {
alert('CAMERA_CHANGE');
});
map.on(GoogleMapsEvent.CAMERA_IDLE).subscribe(
() => {
alert('CAMERA_IDLE');
});
map.on(GoogleMapsEvent.MAP_READY).subscribe(
() => {
alert('MAP_READY');
});
map.on(GoogleMapsEvent.MAP_LOADED).subscribe(
() => {
alert('MAP_LOADED');
});
map.on(GoogleMapsEvent.MAP_WILL_MOVE).subscribe(
() => {
alert('MAP_WILL_MOVE');
});
map.on(GoogleMapsEvent.MAP_CLOSE).subscribe(
() => {
alert('MAP_CLOSE');
});
map.on(GoogleMapsEvent.MARKER_CLICK).subscribe(
() => {
alert('MARKER_CLICK');
});
map.on(GoogleMapsEvent.OVERLAY_CLICK).subscribe(
() => {
alert('OVERLAY_CLICK');
});
map.on(GoogleMapsEvent.INFO_CLICK).subscribe(
() => {
alert('INFO_CLICK');
});
map.on(GoogleMapsEvent.MARKER_DRAG).subscribe(
() => {
alert('MARKER_DRAG');
});
map.on(GoogleMapsEvent.MARKER_DRAG_START).subscribe(
() => {
alert('MARKER_DRAG_START');
});
map.on(GoogleMapsEvent.MARKER_DRAG_END).subscribe(
() => {
alert('MARKER_DRAG_END');
});
});
});
});
});
}
}
找不到问题所在,似乎是依赖关系或插件问题。您可能必须首先构建应用程序或在模拟器上运行应用程序,因为google map SDK for ionic不在浏览器上运行 在emulator上使用
爱奥尼亚运行android运行应用程序
或构建应用程序
爱奥尼亚构建android
我找到了一个关于的教程,它提供了爱奥尼亚应用程序和谷歌地图SDK的基本集成。要在爱奥尼亚2中实现更高级的谷歌地图,请查看。只需按照教程熟悉集成的代码实现即可。这可能是另一种解决方案,但我使用的是GoogleMapsJavaScriptAPI
import {Component} from "@angular/core";
import {
GoogleMap,
GoogleMapsEvent,
GoogleMapsLatLng,
GoogleMapsMarker,
Geolocation
} from 'ionic-native';
@Component({
selector: 'page-about',
templateUrl: 'about.html'
})
export class AboutPage {
private _latitude: number;
private _longitude: number;
constructor() {}
ngAfterViewInit() {
let map = new GoogleMap(document.getElementById('map'));
// when the map is ready
map.one(GoogleMapsEvent.MAP_READY).then(() => {
Geolocation.getCurrentPosition().then(pos => {
this._latitude = pos.coords.latitude;
this._longitude = pos.coords.longitude;
// move the camera
map.moveCamera({
target: new GoogleMapsLatLng(this._latitude, this._longitude),
zoom: 18,
tilt: 30
}).then(() => {
// add a marker
map.addMarker({
position: new GoogleMapsLatLng(this._latitude, this._longitude),
title: 'You are here!'
})
// show marker info
.then((marker: GoogleMapsMarker) => {
marker.showInfoWindow();
// listen to all available events
map.on(GoogleMapsEvent.MAP_CLICK).subscribe(
() => {
alert('MAP_CLICK');
});
map.on(GoogleMapsEvent.MAP_LONG_CLICK).subscribe(
() => {
alert('MAP_LONG_CLICK');
});
map.on(GoogleMapsEvent.MY_LOCATION_CHANGE).subscribe(
() => {
alert('MY_LOCATION_CHANGE');
});
map.on(GoogleMapsEvent.MY_LOCATION_BUTTON_CLICK).subscribe(
() => {
alert('MY_LOCATION_BUTTON_CLICK');
});
map.on(GoogleMapsEvent.INDOOR_BUILDING_FOCUSED).subscribe(
() => {
alert('INDOOR_BUILDING_FOCUSED');
});
map.on(GoogleMapsEvent.INDOOR_LEVEL_ACTIVATED).subscribe(
() => {
alert('INDOOR_LEVEL_ACTIVATED');
});
map.on(GoogleMapsEvent.CAMERA_CHANGE).subscribe(
() => {
alert('CAMERA_CHANGE');
});
map.on(GoogleMapsEvent.CAMERA_IDLE).subscribe(
() => {
alert('CAMERA_IDLE');
});
map.on(GoogleMapsEvent.MAP_READY).subscribe(
() => {
alert('MAP_READY');
});
map.on(GoogleMapsEvent.MAP_LOADED).subscribe(
() => {
alert('MAP_LOADED');
});
map.on(GoogleMapsEvent.MAP_WILL_MOVE).subscribe(
() => {
alert('MAP_WILL_MOVE');
});
map.on(GoogleMapsEvent.MAP_CLOSE).subscribe(
() => {
alert('MAP_CLOSE');
});
map.on(GoogleMapsEvent.MARKER_CLICK).subscribe(
() => {
alert('MARKER_CLICK');
});
map.on(GoogleMapsEvent.OVERLAY_CLICK).subscribe(
() => {
alert('OVERLAY_CLICK');
});
map.on(GoogleMapsEvent.INFO_CLICK).subscribe(
() => {
alert('INFO_CLICK');
});
map.on(GoogleMapsEvent.MARKER_DRAG).subscribe(
() => {
alert('MARKER_DRAG');
});
map.on(GoogleMapsEvent.MARKER_DRAG_START).subscribe(
() => {
alert('MARKER_DRAG_START');
});
map.on(GoogleMapsEvent.MARKER_DRAG_END).subscribe(
() => {
alert('MARKER_DRAG_END');
});
});
});
});
});
}
}