Sunday, 15 February 2015

xcode - Calculate distance between annotation and user -



xcode - Calculate distance between annotation and user -

i trying calculate distance between user , selected (clicked) annotation. code seemed ok me, exc_bad_instruction error @ var distance = ... line. why?

fatal error: unexpectedly found nil while unwrapping optional value @ var distance line

var locationmanager = cllocationmanager() var userlocation: mkuserlocation! func mapview(mapview: mkmapview!, didselectannotationview view: mkannotationview!) { allow location = cllocation( latitude: view.annotation.coordinate.latitude, longitude: view.annotation.coordinate.longitude ) println(location.coordinate.longitude) var distance : cllocationdistance = locationmanager.location.distancefromlocation(location) println(distance) } func locationmanager(manager:cllocationmanager, didupdatelocations locations:[anyobject]) { var latvalue = locationmanager.location.coordinate.latitude var lonvalue = locationmanager.location.coordinate.longitude allow location = cllocationcoordinate2d(latitude: latvalue, longitude: lonvalue) allow span = mkcoordinatespanmake(1, 1) allow part = mkcoordinateregion(center: location, span: span) mapview.setregion(region, animated: true) }

xcode swift locationmanager

No comments:

Post a Comment