简体   繁体   English

如何为Google地图IOS设置可见区域/缩放级别以显示添加到mapview的所有标记

[英]How to set visible region/zoom level for google maps IOS to show all markers added to the mapview

I have used Google maps in ios app, I wanna set zoom level dynamically depends on the search i made over map. 我在ios应用程序中使用了Google地图,我想动态设置缩放级别取决于我在地图上进行的搜索。 Basically am adding pins by searching with city names or lat/long query. 基本上我通过搜索城市名称或纬度/经度查询来添加引脚。 after every search am adding pins & i need to show all added markers by the recent search i made. 每次搜索后都添加了针脚,我需要通过最近的搜索显示所有添加的标记。

@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))

请参阅此答案 ,了解迭代给定标记数组然后相应地设置边界的简单方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM