我在阅读Google maps for swift的文档,但与Android相比,我没有找到一种方法来设置我的Map上的“缩放控件”,默认情况下是禁用的。Google Maps iOS SDK是否有显示控件的方法?
Google Maps iOS SDK
e5njpo681#
我认为@Scriptable是对的,文档中没有iOS SDK的Zoom Controls部分。好吧,我做了我自己的(和非常基本的)控件。x1c 0d1x保持这个顺序(MapView,Button,Button),否则,你看不到按钮。
iOS SDK
Zoom Controls
MapView
Button
的首先,您必须选择UIVIew并将类更改为GSMMapView在MapViewController中,
UIVIew
GSMMapView
MapViewController
import Foundation import UIKit import GoogleMaps class MapViewController: UIViewController { struct Place { let id: Int let name: String let lat: CLLocationDegrees let lng: CLLocationDegrees let icon: String } @IBOutlet weak var mapView: GMSMapView! var markerDict: [Int: GMSMarker] = [:] var zoom: Float = 15 override func viewDidLoad() { super.viewDidLoad() let camera = GMSCameraPosition.camera(withLatitude: 34.1381168, longitude: -118.3555723, zoom: zoom) self.mapView.camera = camera do { if let styleURL = Bundle.main.url(forResource: "style", withExtension: "json") { mapView.mapStyle = try GMSMapStyle(contentsOfFileURL: styleURL) } else { NSLog("Unable to find style.json") } } catch { NSLog("One or more of the map styles failed to load. \(error)") } let places = [ Place(id: 0, name: "MrMins", lat: 34.1331168, lng: -118.3550723, icon: "i01"), ] for place in places { let marker = GMSMarker() marker.position = CLLocationCoordinate2D(latitude: place.lat, longitude: place.lng) marker.title = place.name marker.snippet = "Custom snipet message \(place.name)" marker.appearAnimation = kGMSMarkerAnimationPop //marker.icon = self.imageWithImage(image: UIImage(named: place.icon)!, scaledToSize: CGSize(width: 35.0, height: 35.0)) marker.map = self.mapView markerDict[place.id] = marker } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } @IBAction func btnZoomIn(_ sender: Any) { zoom = zoom + 1 self.mapView.animate(toZoom: zoom) } @IBAction func btnZoomOut(_ sender: Any) { zoom = zoom - 1 self.mapView.animate(toZoom: zoom) } }
字符串
ghhaqwfi2#
你应该捕捉当前的缩放值,因为如果你硬编码缩放值,用户将使用不仅按钮,但按钮和手势时,用户将按下按钮后,通过手势缩小,你会缩放到旧的缩放值(非常接近Map)要修复这个时刻,你应该在这里捕捉缩放值(在GMSMapViewDelegate中)
func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition) { zoom = mapView.camera.zoom }
字符串所有的代码都是这样的
class A: UIViewController { var zoom: Float = 15 @IBAction func ZoomInButtonPressed(_ sender: UIButton) { let nextZoom = zoom + 1 mapView.animate(toZoom: nextZoom) } } extension A: GMSMapViewDelegate { func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition) { zoom = mapView.camera.zoom } }
型
2条答案
按热度按时间e5njpo681#
我认为@Scriptable是对的,文档中没有
iOS SDK
的Zoom Controls
部分。好吧,我做了我自己的(和非常基本的)控件。x1c 0d1x
保持这个顺序(
MapView
,Button
,Button
),否则,你看不到按钮。的
首先,您必须选择
UIVIew
并将类更改为GSMMapView
在
MapViewController
中,字符串
ghhaqwfi2#
你应该捕捉当前的缩放值,因为如果你硬编码缩放值,用户将使用不仅按钮,但按钮和手势时,用户将按下按钮后,通过手势缩小,你会缩放到旧的缩放值(非常接近Map)
要修复这个时刻,你应该在这里捕捉缩放值(在GMSMapViewDelegate中)
字符串
所有的代码都是这样的
型