Get place names using CLGeocoder (not street names) - iphone

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);
}
}];
}

Related

Getting coordinates based in direction in Google Maps/Apple Maps in Objective-C

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.

CLGeocoder Only Returning One Placemark

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.

iOS CoreLocation CLGeocoder giving incomplete UK postcode

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.

Use CurrentLocation for Continent iPhone

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

iPhone reverse geocoding: give all possible streets/suburbs?

I know Core Location isnt always accurate on the iPhone. Is there a way to use the location (lat/long) along with the accuracy to then grab all of the possible suburbs/streets in that area?
So instead of using the reverse geocoding and having it guess the 'best possible suburb/street, is there a way to make it give an array (or in some other format) of all the possible suburbs/streets that it could consider?
Thanks!!
So, the best approach to do this, is using the Google maps API. For example, take a look ate the following url: http://maps.google.com/maps/geo?q=38.4417077,-90.7122047&output=xml
As you can see, for this pair (latitude, longitude) you have 10 possible placemarks for this coordinates.
The documentation for this you can find at: http://code.google.com/apis/maps/documentation/geocoding/index.html
You can see that you get the info in XML, JSON, CSV.
Take a look at the status code, it is important to verify if the request was successful (usually 200 or 200 and something).
So, how to use it VFN?
It is simple.
double latitude = coordinate.latitude;
double longitude = coordinate.longitude;
NSString *urlString = [NSString stringWithFormat:#"http://maps.google.com/maps/geo?q=%f,%f&output=xml", latitude, longitude];
NSURL *url = [NSURL URLWithString:urlString];
NSString *locationString = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
on locationString is the response from Google Geocoder, now you can use the info as you want. Remember to first check the status code, and than parse the info. If you want only the first placemark that is selected by Google Geocoder, I would suggest you to use the output in CSV, that is easy to work with.
If you have any queries, let me know!
Cheers,
VFN