根据Radius Google Maps iOS SDK更改相机缩放 [英] Change Camera Zoom based on Radius Google Maps iOS SDK

查看:122
本文介绍了根据Radius Google Maps iOS SDK更改相机缩放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一款应用,根据您当前位置的半径显示某些标记。半径在100-5000米之间。我用 UISlider 更改半径并重新绘制 GMSCircle

I am working on an app that displays certain markers based on a radius around your current location. The radius is between 100 - 5000 meters. I change the radius with an UISlider and redraw the GMSCircle.

我的问题是我想根据滑块值更新相机变焦,但我不知道要分割的比例。

My problem is that I want to update the camera zoom according to the slider value but I don't have an idea by which scale to divide.

这是如何在 viewDidLoad 方法中创建相机,其中初始缩放值为15:

This is how I create the camera in the viewDidLoad method where the initial zoom value is 15:

GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:locationManager.location.coordinate.latitude longitude:locationManager.location.coordinate.longitude  zoom:15];

这是我正在处理的截图。

Here's a screenshot of what I am working on.

有谁知道我应该使用什么比例来相应地移动缩放?

Does anyone know what scale should I use to move the zoom accordingly?

非常感谢!

Granit

推荐答案

在Saxon Druce的帮助下,我终于做到了。

With the help of Saxon Druce,finally I did it.

class MapUtil {

class func translateCoordinate(coordinate: CLLocationCoordinate2D, metersLat: Double,metersLong: Double) -> (CLLocationCoordinate2D) {
    var tempCoord = coordinate

    let tempRegion = MKCoordinateRegionMakeWithDistance(coordinate, metersLat, metersLong)
    let tempSpan = tempRegion.span

    tempCoord.latitude = coordinate.latitude + tempSpan.latitudeDelta
    tempCoord.longitude = coordinate.longitude + tempSpan.longitudeDelta

    return tempCoord
}

class func setRadius(radius: Double,withCity city: CLLocationCoordinate2D,InMapView mapView: GMSMapView) {

    let range = MapUtil.translateCoordinate(city, metersLat: radius * 2, metersLong: radius * 2)

    let bounds = GMSCoordinateBounds(coordinate: city, coordinate: range)

    let update = GMSCameraUpdate.fitBounds(bounds, withPadding: 5.0)    // padding set to 5.0

    mapView.moveCamera(update)

    // location
    let marker = GMSMarker(position: city)
    marker.title = "title"
    marker.snippet = "snippet"
    marker.flat = true
    marker.map = mapView

    // draw circle
    let circle = GMSCircle(position: city, radius: radius)
    circle.map = mapView
    circle.fillColor = UIColor(red:0.09, green:0.6, blue:0.41, alpha:0.5)

    mapView.animateToLocation(city) // animate to center
}

}

这篇关于根据Radius Google Maps iOS SDK更改相机缩放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆