【发布时间】:2016-10-17 15:00:02
【问题描述】:
我正在 nativescript+Angular2 上构建一个应用程序。我已经从 npm 下载了“nativescript-google-maps-sdk”插件。如果我启用setMyLocationEnabled(true),我会在屏幕右上角看到“我的位置”按钮,单击它会将我带到我的实际位置。
我想做的是以编程方式获取这些坐标,因为我将需要它们进行其他操作(标记、邻近值等)。
浏览他们的代码,但找不到他们如何获得这个当前位置。 gMap.getMyLocation() 已被弃用,所以我不能使用它,基于这里写的:https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap
我们应该使用 FusedLocationProviderApi。如果这个插件不使用它,那么它如何获取当前位置?
谁能解释一下?
mapReady(args) {
console.log("Map Ready");
var gMap = args.gMap;
gMap.setMyLocationEnabled(true);
// gMap.getMyLocation(); deprecated
// need to get current location coordinates, somehow...
}
【问题讨论】:
-
为了能够获取当前位置,您可以使用
nativescript-geolocation插件。如需进一步帮助,您可以查看此示例 - github.com/NativeScript/nativescript-sdk-examples-ng/tree/…。 -
我已经在使用 nativescript-geolocation 插件来获取我的坐标,但后来它击中了我——如果 gmaps 已经有一个内置功能来定位你,为什么我还需要使用 2 个插件。我想没有办法解决这个问题。那就坚持下去,谢谢。 p.s.我猜这些例子已经过时了,在那里看到一个“位置”插件,现在已弃用。
-
在 NativeScript 1.5.0 中,
Location module已被弃用,并已移至名为nativescript-geolocation的外部插件,该插件由 NativeScript 开发团队提供支持。
标签: google-maps-android-api-2 nativescript angular2-nativescript