angular - 在谷歌地图上更改“我的位置”的位置
问题描述
我正在使用 google-maps-SDK,我希望用户能够将相机设置到他的位置。我将 map.settings.myLocationButtonEnabled 设置为 true,然后我得到了按钮,但我想对其进行一些自定义。我想更改它在地图上的位置并添加一些 CSS 功能。我该怎么做?在我的 HTML 中,我有
<maps:mapView (mapReady)="onMapReady(map)" #map></maps:mapView>
在我的 TS 中,我有
onMapReady(map: MapView) {
this.mainMap = map;
map.settings.myLocationButtonEnabled = true;
}
解决方案
您不能像那样更改默认按钮。但是,您可以创建自己的位置按钮,它简单易行。在 html 中,在地图上添加一个按钮:
<button (tap)="setMyLocation()"></button>
在你的 ts 添加这个:
import * as geolocation from "nativescript-geolocation";
setMyLocation(){
geolocation.getCurrentLocation({ desiredAccuracy: Accuracy.high, maximumAge: 1000, timeout: 20000 }).then(loc => {
this.mainMap.latitude = loc.latitude;
this.mainMap.longitude = loc.longitude;
})
}
推荐阅读
- angular - Angular 2 Reactive Forms中FormArray内的FormGroup
- c - 在字符串中搜索子字符串
- flask - 将 Neo4j Java API 与 Python Flask 应用程序一起使用 - 如何?
- excel - Excel VBA中具有多个条件的行总和
- python - 使用索引更改列名
- sql - 根据 SQL Server 中的条件执行 While 循环
- bash - 如何使用 lynx 解析 http://www.worldometers.info/pt/ 网站中的数据?
- javascript - 检查表与 JavaScript 和 jQuery 的重叠
- sql - 我想在其他列所需条件的基础上插入 Ranks 列的值
- c# - 连接额外显示器时 Winform 窗口显示和行为变化