更改 "My location" 在 google 地图上的位置
Change location of "My location" on google maps
我正在使用 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;
})
}
我正在使用 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;
})
}