我在 ios 应用程序中使用了谷歌地图,我想动态设置缩放级别取决于我在地图上进行的搜索。基本上是通过搜索城市名称或纬度/经度查询来添加图钉。每次搜索后,我都会添加图钉,并且我需要通过我最近的搜索显示所有添加的标记。
问问题
4519 次
2 回答
5
@IBOutlet weak var mapView: GMSMapView!
let camera = GMSCameraPosition.cameraWithLatitude(23.0793, longitude:
72.4957, zoom: 5)
mapView.camera = camera
mapView.delegate = self
mapView.myLocationEnabled = true
*** arry has dictionary object which has value of Latitude and Longitude. ***
let path = GMSMutablePath()
for i in 0..<arry.count {
let dict = arry[i] as! [String:AnyObject]
let latTemp = dict["latitude"] as! Double
let longTemp = dict["longitude"] as! Double
let marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: latTemp, longitude: longTemp)
marker.title = "Austrilia"
marker.appearAnimation = kGMSMarkerAnimationNone
marker.map = self.mapView
path.addCoordinate(CLLocationCoordinate2DMake(latTemp, longTemp))
}
let bounds = GMSCoordinateBounds(path: path)
self.mapView!.animateWithCameraUpdate(GMSCameraUpdate.fitBounds(bounds, withPadding: 50.0))
于 2016-05-31T08:02:02.500 回答
1
有关迭代给定标记数组然后相应设置边界的简单方法,请参见此答案。
于 2014-06-13T15:31:20.910 回答