我正在開發一個應用程序,我在使用谷歌地圖。 我希望有一個標記引腳穩定在屏幕的中心,如果我移動地圖的引腳不應該移動。移動谷歌地圖,但不是像Uber標記
當我離開地圖時,我想要保存穩定標記ID的地圖。
任何幫助將理解
我正在開發一個應用程序,我在使用谷歌地圖。 我希望有一個標記引腳穩定在屏幕的中心,如果我移動地圖的引腳不應該移動。移動谷歌地圖,但不是像Uber標記
當我離開地圖時,我想要保存穩定標記ID的地圖。
任何幫助將理解
你可以用這個東西
mapView.delegate = self;
func mapView(_ mapView: GMSMapView, idleAt position: GMSCameraPosition) {
let coordinate = mapView.projection.coordinate(for: markerView.center)
print("latitude " + "\(coordinate.latitude)" + " longitude " + "\(coordinate.longitude)")
}
現在,你需要添加在你的MapView的頂部只是一個ImageView的中心,它會像超級一樣工作。
記住針圖標的高度應該加倍。
謝謝,這工作完美,因爲我想 –
你可以添加在地圖視圖之上的圖像層,含有指向屏幕的中心銷的圖像。當用戶離開地圖時,從屏幕中心選取位置。
修復您視圖中心的標記視圖。
在您的頂視圖中添加GMSMapview。
將代表設置爲您的地圖視圖。
GMap.delegate = self; // Add delegate - GMSMapViewDelegate to your viewcontroller
要檢測用戶拖動地圖:
func mapView(_ mapView: GMSMapView, idleAt position: GMSCameraPosition) {
let coo = GMap.projection.coordinate(for: markerView.center)
selectedLocation = CLLocation(latitude: coo.latitude, longitude: coo.longitude)
getAddress() //get address of your selected location
}
這裏GMap是什麼: - let coo = GMap.projection.coordinate(for:markerView.center) –
GMap是GMSMapView的一個實例。用你的mapview替換它 –
你嘗試過什麼到目前爲止,你可以使用這個圖標? –