cllocationcoordinate2d

CLLocationCoordinate2D can't be instantiated

做~自己de王妃 提交于 2021-01-20 07:32:10
问题 I am trying to create some "CLLocation"s from data that I've read from a file. The first step is to instantiate a "CLLocationCoordinate2D" to be fed into the initializer for CLLocation. I'm trying out my ideas in a Playground and this very simple code generates a runtime error: import CoreLocation let lat = 48.8 let lon = -122.3 let point2D = CLLocationCoordinate2D(latitude: lat, longitude: lon) Error message is error: Execution was interrupted, reason: signal SIGABRT. The process has been

How to Fix: Cannot assign value of type 'CLLocationDegrees' (aka 'Double') to type 'Float!' in Swift 3

人走茶凉 提交于 2020-01-24 09:48:26
问题 I get a coordinate from my google map and I want to assign it to a float variable, but it shows this error: Cannot assign value of type 'CLLocationDegrees' (aka 'Double') to type 'Float!' func markerButtonClicked(sender:MapButton) { let coord = self.getCenterCoordinate() let addressObj = Address() addressObj.latitude = coord.latitude addressObj.longitude = coord.longitude } func getCenterCoordinate() -> (CLLocationCoordinate2D) { let location = CGPoint(x:self.mView.bounds.size.width/2,y:self

How to get Lat Long of tapped location in Google Map iOS Swift

你。 提交于 2020-01-07 02:51:22
问题 I am trying to get the CLLocationCoordinate2D object from the tapped location in a google map view. But it always return me -180.0, -180.0 as lat,long like this: CLLocationCoordinate2D(latitude: -180.0, longitude: -180.0) I am using following code for this: override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) { let touchpoint = touches.first if let touch = touches.first { var point: CGPoint = touch.locationInView(self.view) let touchMapCoordinate:

Convert GPS coordinates to a city name / address in Swift

邮差的信 提交于 2019-12-22 05:25:09
问题 I have a latitude/longitude location that I want to convert to the location name String in Swift. What is the best way to do this? i believe it's best to use the reverseGeocodeLocation function but not exactly sure how to. This is what I have so far: func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) { if (locationFixAchieved == false) { locationFixAchieved = true var locationArray = locations as NSArray var locationObj = locationArray.lastObject as

Convert GPS coordinates to a city name / address in Swift

自作多情 提交于 2019-12-22 05:25:03
问题 I have a latitude/longitude location that I want to convert to the location name String in Swift. What is the best way to do this? i believe it's best to use the reverseGeocodeLocation function but not exactly sure how to. This is what I have so far: func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) { if (locationFixAchieved == false) { locationFixAchieved = true var locationArray = locations as NSArray var locationObj = locationArray.lastObject as

iOS Swift - CLGeocoder completionHandler block

你离开我真会死。 提交于 2019-12-19 04:57:07
问题 I'm trying to parse a location (CLLocation) into a String. func locationToString (currentLocation: CLLocation) -> String? { var whatToReturn: String? CLGeocoder().reverseGeocodeLocation(currentLocation, completionHandler: { (placemarks: [AnyObject]!, error: NSError!) in if error == nil && placemarks.count > 0 { let location = placemarks[0] as CLPlacemark whatToReturn = "\(location.locality) \(location.thoroughfare) \(location.subThoroughfare)" } }) return whatToReturn } Obviously,

How to rotate car marker image in Mapbox 3.6?

天涯浪子 提交于 2019-12-13 16:53:22
问题 I want to rotate marker image as per the route direction.I had implemented map using Map box SDK. Coordinates & directions are fetched through webservice. I tried imageForMarker but it didnt work. Implemetation is as follow func mapView(_ mapView: MGLMapView, imageFor annotation: MGLAnnotation) -> MGLAnnotationImage? { let img = imageRotatedByDegrees(oldImage: UIImage(named: "car")!, deg: CGFloat(self.bearing)) return MGLAnnotationImage(image: img, reuseIdentifier: "car") } func

Can't compare two CLLocationCoordinate2Ds (negative zero??)

﹥>﹥吖頭↗ 提交于 2019-12-11 06:53:20
问题 I'm having the hardest time comparing two (what should be identical) CLLocationCoordinate2D structs in my iOS app. For some reason no matter how I compare them, the latitude just won't say it's equal. The code: double dlat = self.mapView.centerCoordinate.latitude - self.centerOnNextView.coordinate.latitude; double dlong = self.mapView.centerCoordinate.longitude - self.centerOnNextView.coordinate.longitude; NSLog(@"dlat: %f dlong: %f, dlat == 0.0: %d, dlat == -0.0: %d, dlong == 0.0: %d, dlong

Reverse function of MKCoordinateRegionMakeWithDistance?

左心房为你撑大大i 提交于 2019-12-07 17:47:09
问题 MapKit's built in function MKCoordinateRegionMakeWithDistance takes distances in meters and turns them into a MKCoordinateRegion : func MKCoordinateRegionMakeWithDistance( _ centerCoordinate: CLLocationCoordinate2D, _ latitudinalMeters: CLLocationDistance, _ longitudinalMeters: CLLocationDistance) -> MKCoordinateRegion is there a reverse function that takes a MKCoordinateRegion and gives me latitudinalMeters and longitudinalMeters? 回答1: MKCoordinateRegion gives a center (latitude and

Realm Object returning nil (Swift)

久未见 提交于 2019-12-07 06:52:19
问题 I have a custom polygon object so I can save map overlays to Realm. I'm able to create this objects successfully, but when I want to retrieve the var polygon object it returns nil. When I print the polygon object, it prints it out fine, with all the data. This is a sample of what it prints out. CustomPolygon { name = Polygon1; id = p1; polygon = Polygon { coordinates = RLMArray <0x7f928ef36230> ( [0] Coordinate { latitude = -36.914167; longitude = 174.904722; }, [1] Coordinate { latitude =