set a constant language to CLPlacemark instance class - iphone

i have looked every where and didn't found an answer for this one.
i'm building an iOS app that uses the location (lat + long) of the user
creating a CLPlacemark, and sends the street + country to the server and get back a respond according to this location.
now the server can get only hebrew values, and the CLPlacemark values are changes according to the operation system of the user.
can i set a const language to the CLPlacemark class instance?
i want that the CLPlacemark will return hebrew regardless from the operation system of the user
here is my code:
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
geoCoder = [[CLGeocoder alloc]init];
[self.geoCoder reverseGeocodeLocation:locationManager.location completionHandler:
^(NSArray *placemarks, NSError *error) {
CLPlacemark *placemark = [placemarks objectAtIndex:0];
placemark.
self.countryTextBox.text =[placemark.addressDictionary valueForKey:#"Country"];
self.citiTextBox.text =[placemark.addressDictionary valueForKey:#"City"];
self.streetTextBox.text =[placemark.addressDictionary valueForKey:#"Street"];
self.zipCodLbl.text =[placemark.addressDictionary valueForKey:#"ZIP"];
//NSLog(#"%#",placemark.addressDictionary);
NSLog(#"%#",[placemark.addressDictionary valueForKey:#"Country"]);
NSLog(#"%#",[placemark.addressDictionary valueForKey:#"City"]);
NSLog(#"%#",[placemark.addressDictionary valueForKey:#"Street"]);
NSLog(#"%#",[placemark.addressDictionary valueForKey:#"ZIP"]);
[locationManager stopUpdatingLocation];
[self.animationBar stopAnimating];
}];
}
thanks a lot.
idan.

after a hard days of searching im finally solve it.
in the view did load just add this line of code:
[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObject:#"he"] forKey:#"AppleLanguages"];
if this will help somebody - great!

Messing with user's system preference is BAD PRACTICE!!
You should use instead:
NSLocale *yourLocal = [[NSLocale alloc] initWithLocaleIdentifier:#"de"];
[geoCoder reverseGeocodeLocation: preferredLocale:yourLocal completionHandler:
^(NSArray *placemarks, NSError *error) {
}];

Related

get nearest locations from my current location

I am currently developing a mobile application for iOS which consists a part that requires to determine the users current location and from current location, i want to find nearest locations.
Is there any way to implement this ??
I have done some coding for finding current location of user.
here is my code snippet,
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder reverseGeocodeLocation:locationManager.location
completionHandler:^(NSArray *placemarks, NSError *error) {
NSLog(#"reverseGeocodeLocation:completionHandler: Completion Handler called!");
if (error){
NSLog(#"Geocode failed with error: %#", error);
return;
}
CLPlacemark *placemark = [placemarks objectAtIndex:0];
NSLog(#"placemarks=%#",[placemarks objectAtIndex:0]);
But my problem is, how will i get nearest other locations ?? from my current location which i already fetched.
Thanks in advance.
Try this...
MKPointAnnotation *ann=[MKPointAnnotaion alloc] init];
CLLocationCoordinate2D point = [ann coordinate];
myLocation = [[CLLocation alloc] initWithLatitude:point.latitude longitude:point.longitude];
CLLocationDistance nearByLocation=[yourCurrentLocation distanceFromLocation:myLocation];

Get Location information Using CLPlaceMark And CLGeocoder

I have been completed drawing the route between two places using ClLocationCoordinate2D on map in ios 6 dynamically.Can anyone please help me out in getting the location name using CLPlacemark and CLGeocoder as reverse geocoder has been deprecated in ios 6.
you can get information like bellow with its Delegate method..
UPDATE:
First Define this variable in .h file like bellow..
NSString *postcode,*locationName;
and use it in bellow method...
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
CLGeocoder * geoCoder = [[CLGeocoder alloc] init];
[geoCoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
for (CLPlacemark * placemark in placemarks) {
postcode = [placemark postalCode];
[postcode retain];
locationName = [placemark name];
[locationName retain];
NSLog(#"\n placemark %#",placemarks);
}
}];
[geoCoder release];
NSLog(#"\n Location Name ==> %# ----> GotPostCode:%#",locationName,postcode);
}
here you can also use other property of CLGeocoder like locality,location,etc...
A CLPlacemark object stores placemark data for a given latitude and longitude. Placemark data includes information such as the country, state, city, and street address associated with the specified coordinate.
Check Link

Find the current location using CLGeocoder Reverse Geocoding

I want to find the current location of user based on latitude and longitude. Prevoiusly I have done it using MKReverseGeocoder but as it is depracated in ios5 ,I going with CLGeocoder.But unable to get the current location .
- (void)viewDidLoad
{
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
[locationManager setDistanceFilter:kCLDistanceFilterNone];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
CLLocation *currentLocation = newLocation;
locationLabelOne=newLocation.coordinate.latitude;
locationLabelTwo=newLocation.coordinate.longitude;
geocoder = [[CLGeocoder alloc] init];
[locationManager stopUpdatingLocation];
[geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error) {
NSLog(#"Found placemarks: %#, error: %#", placemarks, error);
if (error == nil && [placemarks count] > 0) {
placemark = [placemarks lastObject];
NSString *get = [NSString stringWithFormat:#"%# %#\n%# %#\n%#\n%#",
placemark.subThoroughfare, placemark.thoroughfare,
placemark.postalCode, placemark.locality,
placemark.administrativeArea,
placemark.country];
} else {
NSLog(#"%#", error.debugDescription);
}
} ];
NSLog(#"%#",placemark);
}
When I NSLog placemark it is returning null.Where I m going wrong?
Possible issues:
1) locationManager:didUpdateToLocation:fromLocation is deprecated iOS 6.0 you should use locationManager:didUpdateLocations: instead.
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray *)locations
{
currentLocation=[locations lastObject];
// rest code will be same
}
2) Also [locationManager stopUpdatingLocation]; sounds fishy. IMO you should not use that in CLLocationManagerDelegatemethod.
P.S.
i) For more details in Forward/Reverse geocoding you can look into Apple's sample code GeocoderDemo
ii) If you use Google API for Reverse Geocoding it will have all data available it has been for years but CLGeocoder will not have complete data like street name, pin code for countries like India. What happens is, when you do Reverse Geocoding requests, you pass co ordinates to Core Location which connects to web service in background(which developer won't come to know) and returns a user-readable address. So it may be possible this web service may not be able to return data as accurate as GOOGLE API.
I had the same problem, then with some experimentation I solved my problem…
Make sure:
-90 < latitude < 90
-180 < longitude < 180
It doesn't seem to perform a basic mod function. Hope that helps...

Using CLGeocoder to find the nearest city

So I've been looking at this for a while, and I can't seem to find a solution anywhere. I am trying to use CLGeocoder in an iOS app to find the nearest city to where the user long taps on the map. I have two main problems:
Even if the user is very zoomed out, and the user taps on say New York (which is what they intend), because of how zoomed out the map is, CLGeocoder often returns a nearby city instead of the more obvious answer of New York. I can't work out how to set the "fuzziness" of the search to overcome this issue.
In many instances the City field is null in the returned placemark object, most commonly in remote areas such as deserts or oceans. In this case, I would ideally want to find the nearest object that actually has City defined, but can't work out how to do this.
For Get all Detail of your Location by using CLGeocoder
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
[currentLocation stopUpdatingLocation];
CLLocation *myLocation = [[CLLocation alloc] initWithLatitude:latitudeValue longitude:longitudeValue];
CLGeocoder * geoCoder = [[CLGeocoder alloc] init];
[geoCoder reverseGeocodeLocation:myLocation completionHandler:^(NSArray *placemarks, NSError *error) {
if(!error)
{
for (CLPlacemark * placemark in placemarks)
{
NSLog(#"placemark.ISOcountryCode %#",placemark.ISOcountryCode);
NSLog(#"placemark.country %#",placemark.country);
NSLog(#"placemark.postalCode %#",placemark.postalCode);
NSLog(#"placemark.administrativeArea %#",placemark.administrativeArea);
NSLog(#"placemark.locality %#",placemark.locality);
NSLog(#"placemark.subLocality %#",placemark.subLocality);
NSLog(#"placemark.subThoroughfare %#",placemark.subThoroughfare);
}
}
else
{
NSLog(#"failed getting city: %#", [error description]);
}
}];
}

CLGeocoder and backward compatibility

I have a simple question.
MKReverseCoder is deprecated and doesn't work since iOS 5. We have to use CLGeocoder. But, there are a lot of people under iOS4. How the new apps can work with iOS4 and iOS5 for geocoding ?
Thanks!
If anyone is trying to move onto CLGeocoder from MKReverseGeocoder then I have written a blog post that might be of help http://jonathanfield.me/jons-blog/clgeocoder-example.html
Basically an example would be, after you have created locationManager and CLGeocoder objects just add this code to your viewDidLoad() and then make some labels or text areas to show the data.
[super viewDidLoad]; locationManager.delegate = self; [locationManager startUpdatingLocation];
locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
[self.CLGeocoder reverseGeocodeLocation: locationManager.location completionHandler:
^(NSArray *placemarks, NSError *error) {
CLPlacemark *placemark = [placemarks objectAtIndex:0];
isoCountryCode.text = placemark.ISOcountryCode;
country.text = placemark.country;
postalCode.text= placemark.postalCode;
adminArea.text=placemark.administrativeArea;
subAdminArea.text=placemark.subAdministrativeArea;
locality.text=placemark.locality;
subLocality.text=placemark.subLocality;
thoroughfare.text=placemark.thoroughfare;
subThoroughfare.text=placemark.subThoroughfare;
//region.text=placemark.region;
}];
MKReverseGeocoder still works with iOS5. It's just deprecated, which means it'll be removed at some later point (like at the release of something like iOS6). So you can continue to use it now without any issues
- (IBAction)geoCodeLocation:(id)sender{
[self.geoCoder reverseGeocodeLocation: locationManager.location completionHandler:
^(NSArray *placemarks, NSError *error) {
CLPlacemark *placemark = [placemarks objectAtIndex:0];
NSLog(#"placemark %#",placemark);
//String to hold address
NSString *locatedAt = [[placemark.addressDictionary valueForKey:#"FormattedAddressLines"] componentsJoinedByString:#", "];
NSLog(#"addressDictionary %#", placemark.addressDictionary);
NSLog(#"placemark %#",placemark.region);
NSLog(#"placemark %#",placemark.country); // Give Country Name
NSLog(#"placemark %#",placemark.locality); // Extract the city name
NSLog(#"location %#",placemark.name);
NSLog(#"location %#",placemark.ocean);
NSLog(#"location %#",placemark.postalCode);
NSLog(#"location %#",placemark.subLocality);
NSLog(#"location %#",placemark.location);
//Print the location to console
NSLog(#"I am currently at %#",locatedAt);
//Set the label text to current location
[locationLabel setText:locatedAt];
}];
For more see property of CLPlacemark