Is there a way to find out the users location Continent? I need to set an AWS entry point based on if they open the app in the US, or Europe. etc.
Is there a way to do this without taking GPS coordinates and making ranges out of them?
If you are in iOS5, you can use GLGeocoder to retrieve the information abotu a current location:
[self.CLGeocoder reverseGeocodeLocation: locationManager.location completionHandler:
^(NSArray *placemarks, NSError *error) {
CLPlacemark *placemark = [placemarks objectAtIndex:0];
//placemark contains the address
}];
CLPlacemark reference:
https://developer.apple.com/library/ios/#DOCUMENTATION/CoreLocation/Reference/CLPlacemark_class/Reference/Reference.html
GLGeocoder reference:
https://developer.apple.com/library/ios/#DOCUMENTATION/CoreLocation/Reference/CLGeocoder_class/Reference/Reference.html
you can reverse geocode a location and get details of where the user is located in text. You use the reverseGeocodeLocation:completionHandler: method on the CLGeocoder class to do this
The completion handler in this method gets passed in an array of CLPlacemark objects, which contain the country code, which you can use to determine the users continent
Although a CLPlacemark object contains lots of useful information, its corresponding continent is not present on it.
I wrote a small category to add a -continent method that returns the corresponding string of the continent based on the -ISOCountryCode of a CLPlacemark.
https://github.com/Hecktorzr/Transcontinental
Related
Is it possible to get coordinates to be used in Google Maps/Apple Maps (depending on iOS versiĆ³n) based on a given direction? I've got the directoon (street and number), the post code and the country (in my case, the country will always be Spain)
Thank you
You need to use Geocoder for that, find a guide here:
Geocoding Location Data
You can find an example at the end of the document:
[geocoder geocodeAddressString:#"1 Infinite Loop"
completionHandler:^(NSArray* placemarks, NSError* error){
for (CLPlacemark* aPlacemark in placemarks)
{
// Process the placemark.
}
}];
As they say, the more info you provide, the more accurate will be.
I want to develop my own maps app. I have been successful in getting a street address at the point of touch on my iPhone using CLGeocoder. Now my question is the following:
I know that you can get information about a place by using a URL like https://maps.google.com/?q=37.324599,-122.031844
If you click on the above URL, it will take you near a church in Cupertino. Now CLGeocoder will only give me its street address i.e. 10110 N De Anza Blvd Cupertino, CA 95014 (I get this). But how to get the actual name i.e. St Joseph of Cupertino Church and Parish?
We can see it on Google Maps that means they must have it stored somewhere right?
Is there any way to access those place names (Not just by CLGeoCoder, any way is fine).
The GeoCoding API in general is for converting between street addresses and coordinates. If you want place names you can probably use the Places API.
(I know this is more of a comment than an answer, but I think I don't have enough reputation points to comment on questions yet)
YOu need t odo like this way after getting lat long use this code by CLLocation manager class
{
CLGeocoder *reverseGeo = [[CLGeocoder alloc] init];
[reverseGeo reverseGeocodeLocation: loc completionHandler:
^(NSArray *placemarks, NSError *error) {
NSLog(#"%#",[placemarks objectAtIndex:0]);
for (CLPlacemark *placemark in placemarks) {
NSLog(#"~~~~~~~~%#",placemark.locality);
}
}];
}
I have a problem with CLGeocoder where when I call geocodeAddressString:withCompletionHandler I only ever get one result back, despite knowing that the inputted string should return more than one value. The class reference even states:
In the case of forward-geocoding requests, multiple placemark objects may be returned if the provided information yielded multiple possible locations.
However, my placemarks array only ever has one item in it:
[geocoderDestination geocodeAddressString:destination completionHandler:^(NSArray *placemarks, NSError *error){
NSLog(#"array count:%i", [placemarks count];}
Thank you for any help.
I have used strings such as "Piccadilly, UK", "Union Street, UK" which have only returned one result. Now that I think about it, putting UK on the end might be the contributing factor.
I dont know about CLGeocoder but if your requirement is a location search another way is to use google location search url http://maps.google.com/maps/geo?q=london which returns a json containing the matched location information.
Instead of UK use United Kingdom it will give you some related result.
Try to add some more info in your address.
One more thing UK is not a valid country code it's GB but it seems that putting GB instead of UK didn't solve the problem.
Moreover CLGeocoder is not as smart as Google Maps API right now because apple uses its own server to decode addresses so you can use Google services.
I've got CoreLocation finding me, and then I'm trying to run reverseGeocodeLocation to figure out the postcode. However, I'm getting an incomplete postcode (SO31 4). Normally you'd expect another two characters after the 4. Here's the code I'm using:
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation {
[self.geocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
CLPlacemark *placemark = [placemarks objectAtIndex:0];
self.postcode.text = placemark.postalCode;
if (self.postcode.text.length > 0)
[self.locationManager stopUpdatingLocation];
}];
}
Notably, I also get similar results trying the lat/long on Google Maps API, you can see here:
http://maps.googleapis.com/maps/api/geocode/json?latlng=50.87138339,-1.30983213&sensor=true
Ideally I want a full postcode. The only alternative that comes to mind is only using the first four characters but I thought I'd ask here first just incase somebody has a better idea.
They don't have the full UK postcode database so you will only ever get this resolution with the Google API's.
You need to use a full postcode database and companies like http://www.postcodeanywhere.co.uk/ sell them.
Late reply - but for what it's worth, the postcode is still a valid postcode without the last 2 letters - it just covers a wider area. It looks odd but it's still more accurate than if you drop the last number.
Just had the same problem with a zip code in Brazil.
Here we have the format 00000-000 and the property postalCode from CLPlacemark was returning only the first five digits.
It's possible to get the full postal code number accessing the addressDictionary property from CLPlacemark. In this NSDictionary we can get the information we need in the values from the keys: ZIP and PostCodeExtension.
I have a question related to Game center achievements. Is it possible to retrieve the name/description of an achievement by its identifier? I am trying to avoid hardcoding every identifier with its corresponding name, so is there a solution that can get the name?
thanks,
Sami
Of course, that's exactly why you have localization support for achievements (as well as leaderboards) inside iTunes Connect.
However, there is no way to ask Game Center about localized info for just one achievement based on it's ID. Instead, you ask for info about all achievements which gives you an array of GKAchievementDescription objects which would be best to put into a dictionary where keys are achievement IDs and then you select a proper GKAchievementDescription object from that dictionary.
NSMutableDictionary *achievementDescriptions = [[NSMutableDictionary alloc] init];
[GKAchievementDescription loadAchievementDescriptionsWithCompletionHandler:^(NSArray *descriptions, NSError *error) {
if (error != nil) {
NSLog(#"Error getting achievement descriptions: %#", error);
}
for (GKAchievementDescription *achievementDescription in descriptions) {
[achievementDescriptions setObject:achievementDescription forKey:achievementDescription.identifier];
}
}];
And then when you want to display info for some achievement:
GKAchievementDescription *achievementDescription = [achievementDescriptions objectForKey:currentAchievement.identifier];
This object gives you a localized title, description for when it is achieved and unachieved, as well as number of points it awards and an image you specified in iTunes Connect.