2017-10-23 3 views
0

マップを移動したときにいつでもマップがユーザーの場所に戻るのを止めることはできますか?その責任 行は次のとおりです。iosmapをズームまたは移動すると、常にユーザーの位置にジャンプSwift

func locationAuthStatus(){ 
    if CLLocationManager.authorizationStatus() == .authorizedWhenInUse{ 
     map.showsUserLocation = true 
    } else { 
     locationManager.requestWhenInUseAuthorization() 
    } 
} 


func centerMapOnLocation(location:CLLocation){ 

    let coordinateRegion = MKCoordinateRegionMakeWithDistance(location.coordinate, regionRadius * 2 , regionRadius * 2) 
    map.setRegion(coordinateRegion, animated: true) 

} 



func mapView(_ mapView: MKMapView, didUpdate userLocation: MKUserLocation){ 
if let location = userLocation.location { 
    //this is the place where you get the new location 


    print("\(location.coordinate.latitude) ") 

    print("\(location.coordinate.longitude)") 

} 
if let loc = userLocation.location { 
    centerMapOnLocation(location: loc) 
    locationManager.stopUpdatingLocation() 


} 
     } 

私は(locationManager.stopUpdationglocationを考えて)この問題を扱うが、マップが移動したとき、彼は即座にそれを更新しているかのように思えるでしょう。 地図のように、時々ユーザーの場所を更新する必要があります。

答えて

0

これは、mapview update delegateでのcenterMapOnLocationを呼び出したことが原因です。それで、mapviewがリロードされるたびに呼び出されるようにします。

SOそれはあなたがユーザーの位置のための注釈ピンを割り当てるだけその時、この関数を呼び出します。

同様:

let region = MKCoordinateRegion(center: CLLocationCoordinate2D(latitude: CLLocationDegrees(Double(strLatitude)!) , longitude: CLLocationDegrees(Double(strLogitude)!)), span: MKCoordinateSpan(latitudeDelta: 0.1, longitudeDelta: 0.1)) 

self.mapView.setRegion(region, animated: true) 
関連する問題