clgeocoder

Convert GPS coordinates to a city name / address in Swift

守給你的承諾、 提交于 2019-12-05 07:18:38
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 CLLocation var coord = locationObj.coordinate var latitude = coord.latitude var longitude = coord

Show address in annotation when pin is dropped on map

▼魔方 西西 提交于 2019-12-05 02:32:57
问题 Currently I can drop pins around the map. Now I want the annotation title to display the address of where the pin is dropped. I've had a look at this but cant get mine to work: Set annotation's title as current address Code in my ViewController.m Updated. - (void)addPinToMap:(UIGestureRecognizer *)gestureRecognizer { if (gestureRecognizer.state != UIGestureRecognizerStateBegan) return; CGPoint touchPoint = [gestureRecognizer locationInView:self.map]; CLLocationCoordinate2D touchMapCoordinate

CLGeocoder reverse geocoding fails with Error Domain=NSURLErrorDomain Code=-1000 -

时光总嘲笑我的痴心妄想 提交于 2019-12-04 06:06:08
With a CLLocation object (content e.g. latitude = 48.196169, longitude = 11.620237), I try to get the current city and country like: if(!geocoder) { geocoder = [[CLGeocoder alloc] init]; } if (geocoder.geocoding) [geocoder cancelGeocode]; [geocoder reverseGeocodeLocation:lo completionHandler:^(NSArray *placemarks, NSError *error) { if(devMode) { NSLog(@"Found placemarks: %@, error: %@", placemarks, error); } if (error == nil && [placemarks count] > 0) { // MY CODE - here placemarks is always (null) } else { if(devMode) NSLog(@"%@", error.debugDescription); } }]; mostly, that works great. But

CLGeocoder returning locations in other countries

拟墨画扇 提交于 2019-12-04 02:48:25
I have the following code: CLGeocoder *_geo = [[CLGeocoder alloc] init]; CLRegion *region = [[CLRegion alloc] initCircularRegionWithCenter: CLLocationCoordinate2DMake(37.33233141, -122.03121860) radius:100 identifier:@"San Francisco"]; [_geo geocodeAddressString:@"Starbucks" inRegion:region completionHandler:^(NSArray *placemarks, NSError *error) { NSLog("%@", placemarks); }]; This returns a Starbucks location in the Philippines even though the center is in the middle of San Francisco. (NSArray *) $3 = 0x07cd9d10 <__NSArrayM 0x7cd9d10>( Starbuck's, Metro Manila, Quezon City, Republic of the

Show address in annotation when pin is dropped on map

冷暖自知 提交于 2019-12-03 20:39:48
Currently I can drop pins around the map. Now I want the annotation title to display the address of where the pin is dropped. I've had a look at this but cant get mine to work: Set annotation's title as current address Code in my ViewController.m Updated. - (void)addPinToMap:(UIGestureRecognizer *)gestureRecognizer { if (gestureRecognizer.state != UIGestureRecognizerStateBegan) return; CGPoint touchPoint = [gestureRecognizer locationInView:self.map]; CLLocationCoordinate2D touchMapCoordinate = [self.map convertPoint:touchPoint toCoordinateFromView:self.map]; CLLocation *currentLocation = [

how to localize address result from reverseGeocodeLocation?

回眸只為那壹抹淺笑 提交于 2019-12-03 03:43:59
问题 My iphone app supposed to resolve address based on latitude and longitude of the user. reverseGeocodeLocation works fine, but results are in english. Is there a way to localize the results to other languages? couldnt find any information about it at apple or anywhere else. The code I use is: CLGeocoder *geocoder = [[[CLGeocoder alloc] init] autorelease]; CLLocation *location = [[[CLLocation alloc] initWithLatitude:coord.latitude longitude:coord.longitude] autorelease]; [geocoder

CLGeocoder reverse geocode from given location

╄→гoц情女王★ 提交于 2019-12-01 20:26:31
问题 Given a longitude and latitude not my current location how can I perform a reverse geocode lookup using GLGeocoder ? self.geoCoder = [[CLGeocoder alloc] init]; self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.delegate = self; // [self.locationManager startUpdatingLocation]; [self.geoCoder reverseGeocodeLocation: locationManager.location completionHandler: ^(NSArray *placemarks, NSError *error) { // [self.locationManager stopUpdatingLocation]; CLPlacemark

CLGeocoder reverse geocode from given location

浪子不回头ぞ 提交于 2019-12-01 19:49:07
Given a longitude and latitude not my current location how can I perform a reverse geocode lookup using GLGeocoder ? self.geoCoder = [[CLGeocoder alloc] init]; self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.delegate = self; // [self.locationManager startUpdatingLocation]; [self.geoCoder reverseGeocodeLocation: locationManager.location completionHandler: ^(NSArray *placemarks, NSError *error) { // [self.locationManager stopUpdatingLocation]; CLPlacemark *placemark = [placemarks objectAtIndex:0]; // Long address // NSString *locatedAt = [[placemark

Updating MKMapView to CLPlacemark returned from CLGeocoder

只愿长相守 提交于 2019-12-01 07:09:28
问题 I want to be able to update the region displayed on a MKMapView by allowing the user to type in an address or location in a UIAlertView. I currently have: if (geocoder.geocoding) [geocoder cancelGeocode]; [geocoder geocodeAddressString:[[alertView textFieldAtIndex:0] text] completionHandler:^(NSArray *placemarks, NSError *error) { if (!error) { NSLog(@"Found a location"); } else { NSLog(@"Error in geocoding"); } NSLog(@"Num found: %d", [placemarks count]); CLPlacemark *placemark = [placemarks

iOS Swift - CLGeocoder completionHandler block

旧巷老猫 提交于 2019-12-01 01:59:27
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, whatToReturn always returns null, because completionHandler runs in the background. I'm having a hard time