NativeScript Google Place Picker
Nativescript Google Place Picker 插件
npm i --save nativescript-google-place-picker

NativeScript 插件用于 Google Place Picker

这是一个跨平台(iOS & Android)的 Nativescript 插件,用于 Google 地点选择器

先决条件

iOS - 已安装 Cocoapods,请参阅安装指南

Android - 已安装最新版本的 Google Play 服务 SDK,请参阅安装指南

Google 地点 API 密钥 - 访问Google 开发者控制台,创建一个项目,并启用 Google 地点 API for AndroidGoogle 地点 API for iOS API。然后在凭据部分创建一个 API 密钥。

Google 地图 API 密钥 - 访问Google 开发者控制台,创建一个项目,并启用 Google Maps Android APIGoogle Maps SDK for iOS API。然后在凭据部分创建一个 API 密钥。

安装

使用 NativeScript CLI 工具安装插件

tns plugin add nativescript-google-place-picker

设置 Google 地图 API

设置 Android API 密钥

将 API 密钥添加到应用清单文件(AndroidManifest.xml)。请参阅Android 添加密钥

插件默认使用 Android play-services-places SDK 的最新版本。如果您需要更改版本,您可以添加一个项目扩展属性 googlePlayServicesVersion,如下所示

//   /app/App_Resources/Android/app.gradle

project.ext {
googlePlayServicesVersion = "+"
}

设置 iOS API 密钥

在您的应用主脚本 app.js 中,使用以下代码添加 API 密钥(将 PUT_API_KEY_HERE 替换为您的密钥)

if(application.ios) {
PlacePicker.iosProvideAPIKey("PUT_API_KEY_HERE");
}

如果您使用 Angular,您需要修改 app.module.ts,如下所示

import * as platform from "platform";
import {PlacePicker} from "nativescript-google-place-picker"
....
if (platform.isIOS) {
PlacePicker.iosProvideAPIKey("PUT_API_KEY_HERE");
}

使用示例

...
public onShowPicker() {
var picker = new PlacePicker()

picker.present()
.then((r)=>{
console.log(r.latitude)
console.log(r.longitude)
})
.catch((e)=>{
console.log("Error: "+e);
})
}
...