快速缩放时标记相对于地图移动

时间:2019-02-14 07:53:00

标签: ios swift google-maps

我对Google地图不熟悉。当我放大时,谷歌地图上的标记会移动。请查看屏幕截图。关于如何使标记相对于地图保持位置有何想法?

enter image description here

enter image description here

func getCoordinate( addressString : String,
                    completionHandler: @escaping(CLLocationCoordinate2D, NSError?) -> Void ) {
    let geocoder = CLGeocoder()
    geocoder.geocodeAddressString(addressString) { (placemarks, error) in
        if error == nil {
            if let placemark = placemarks?[0] {
                let location = placemark.location!

                completionHandler(location.coordinate, nil)
                return
            }
        }

        completionHandler(kCLLocationCoordinate2DInvalid, error as NSError?)
    }
}

这是我的代码:

     func determineMyCurrentLocation() {
        locationManager = CLLocationManager()
        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        locationManager.requestAlwaysAuthorization()

        if CLLocationManager.locationServicesEnabled() {
            locationManager.startUpdatingLocation()
            locationManager.startUpdatingHeading()
        }
    }

  func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        locationManager.delegate = nil
        locationManager.stopUpdatingLocation()

        let userLocation = locations.last
        let lat = (userLocation!.coordinate.latitude)
        let long = (userLocation!.coordinate.longitude)
        let camera = GMSCameraPosition.camera(withLatitude: lat, longitude: long, zoom: 10.0)
        mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
        mapView!.isMyLocationEnabled = true
        mapView!.animate(to: camera)
        view = mapView

        showPartyMarkers(lat: lat, long: long)

    } 
  func showPartyMarkers(lat: Double, long: Double) {
    mapView!.clear()
    for i in 0...properties.count - 1 {

        let marker=GMSMarker()

        ImageService.getImage(withURL: URL(string: properties[i].gallery[0])!) { (image) in
            let customMarker = CustomMarkerView(frame: CGRect(x: 0, y: 0, width: 150 , height: 180), image: image!, borderColor: UIColor.darkGray, tag: i)
            marker.iconView=customMarker
        }

        getCoordinate(addressString: properties[i].address) { (CLLocationCoordinate2D, error) in
            print(CLLocationCoordinate2D)
            if error != nil {
                print(error)
                return
            }
            marker.position = CLLocationCoordinate2D
            marker.map = self.mapView
        }
    }

}
   func getCoordinate( addressString : String,
                    completionHandler: @escaping(CLLocationCoordinate2D, NSError?) -> Void ) {
    let geocoder = CLGeocoder()
    geocoder.geocodeAddressString(addressString) { (placemarks, error) in
        if error == nil {
            if let placemark = placemarks?[0] {
                let location = placemark.location!

                completionHandler(location.coordinate, nil)
                return
            }
        }

        completionHandler(kCLLocationCoordinate2DInvalid, error as NSError?)
    }
}

预先感谢

0 个答案:

没有答案
相关问题