gpt4 book ai didi

ios - 如何使用 Swift 启用 Google map 缩放控件

转载 作者:搜寻专家 更新时间:2023-10-30 22:06:46 25 4
gpt4 key购买 nike

我正在阅读 Google maps for swift 的文档,但与 Android 相比,我没有找到在我的 map 上设置“缩放控件”的方法,默认情况下是禁用的。

是否存在使用 Google Maps iOS SDK 显示控件的方法?

最佳答案

我认为@Scriptable 是正确的,文档中没有针对 iOS SDKZoom Controls 部分。

好吧,我制作了自己的(非常基本的)控件。 enter image description here

请保持此顺序(MapViewButtonButton),否则您将看不到按钮。

enter image description here

第一个,您必须选择您的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)
}


}

关于ios - 如何使用 Swift 启用 Google map 缩放控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43878562/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com