ios – Google地图缩小到GPS和标记

我试图在地图上显示三件事情:
GPS(当前位置),Marker 1,Marker 2,但我不知道我做得对不对!这是我的代码
self.startMarker.position = CLLocationCoordinate2D(latitude: self.startLatitude,longitude: self.startLongitude)
 self.startMarker.icon = #imageLiteral(resourceName: "Pin Start")
 self.startMarker.map = self.mapView


 self.endMarker.position = CLLocationCoordinate2D(latitude: self.endLatitude,longitude: self.endLongitude)
 self.endMarker.icon = #imageLiteral(resourceName: "Pin End")
 self.endMarker.map = self.mapView


 let southWest = CLLocationCoordinate2DMake(self.startLatitude,self.startLongitude)
 let northEast = CLLocationCoordinate2DMake(self.endLatitude,self.endLongitude)
 let bounds = GMSCoordinateBounds(coordinate: northEast,coordinate: southWest)
 let camera = self.mapView.camera(for: bounds,insets:.zero)
 self.mapView.camera = camera!

更多代码

// MARK: - Google Map

private func locationManager(manager: CLLocationManager,didChangeAuthorizationStatus status: CLAuthorizationStatus) {
            if status == CLAuthorizationStatus.authorizedWhenInUse {
                mapView.isMyLocationEnabled = true
            }
          }
func locationManager(_ manager: CLLocationManager,didUpdateLocations locations: [CLLocation]) {
            let newLocation = locations.last
            mapView.camera = GMSCameraPosition.camera(withTarget: newLocation!.coordinate,zoom: 14)
            mapView.isMyLocationEnabled = true
        }

结果是这样的:

我需要的 :

EDITED

if let myLocation = self.mapView.myLocation {

let path = GMSMutablePath()
path.add(myLocation.coordinate)
path.add(self.startMarker.position)
path.add(self.endMarker.position)

let bounds = GMSCoordinateBounds(path: path)
                                        self.mapView.animate(with: GMSCameraUpdate.fit(bounds,withPadding: 40))

}

解决方法

显示屏幕界限的所有标记

在这里我试图给你一个简单的例子,希望这将有助于你.
使用此功能,您可以在屏幕上显示任意数量标记.

例:

let path = GMSMutablePath()
for var i in 0 ..< array.count
{
    let lat = Double(array.objectAtIndex(i).valueForKey(lattitude) as! String)
    let long = Double(arrayr.objectAtIndex(i).valueForKey(longitude) as! String)      
    marker.position = CLLocationCoordinate2DMake(lat!,long!)
    path.addCoordinate(marker.position)
    marker.map = self.mapView
}
let bounds = GMSCoordinateBounds(path: path)
self.mapView!.animateWithCameraUpdate(GMSCameraUpdate.fitBounds(bounds,withPadding: 30.0))

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...