首页 > 解决方案 > 在谷歌地图上更改“我的位置”的位置

问题描述

我正在使用 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;
    }

标签: angulargoogle-mapslocationnativescript

解决方案


您不能像那样更改默认按钮。但是,您可以创建自己的位置按钮,它简单易行。在 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;
    })
}

推荐阅读