【问题标题】:How to set visible region/zoom level for google maps IOS to show all markers added to the mapview如何为谷歌地图IOS设置可见区域/缩放级别以显示添加到地图视图的所有标记
【发布时间】:2013-10-22 10:13:58
【问题描述】:

我在 ios 应用程序中使用了谷歌地图,我想根据我在地图上进行的搜索动态设置缩放级别。基本上是通过搜索城市名称或纬度/经度查询来添加图钉。每次搜索后我都会添加图钉,我需要通过最近的搜索显示所有添加的标记。

【问题讨论】:

  • 我们可以为此设置可见区域

标签: ios google-maps google-maps-sdk-ios


【解决方案1】:
@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))

【讨论】:

    【解决方案2】:

    See this answer 提供一种简单的方法来迭代给定的标记数组,然后相应地设置边界。

    【讨论】:

      猜你喜欢
      • 2011-01-22
      • 2010-10-28
      • 1970-01-01
      • 2017-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多