2016-09-09 87 views
0

需要什麼樣的代碼才能使我的酒吧按鈕定位並縮放到用戶的位置,例如在Google地圖中?我試過以下內容:導航按鈕用戶位置

if Navigationbutton != nil { 
    Navigationbutton.target = MKMapView() 
    Navigationbutton.action = CLLocationCoordinate2D (latitude: location!.coordinate.latitude, longitude: location.coordinate.longitude) 

回答

0

這就是您尋找的是:

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { 
    // Get location 
    let location:CLLocationCoordinate2D = manager.location!.coordinate 

    // Center map 
    let span = MKCoordinateSpanMake(0.014, 0.014) 
    let region = MKCoordinateRegion(center: location, span: span) 
    mapView.setRegion(region, animated: true) 
}