iPhone reverse geocoding: give all possible streets/suburbs? - iphone

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

Related

Get place names using CLGeocoder (not street names)

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

how can i query google places for country specific cuisine?

i am trying to accomplish country specific Cuisine places, means like mexican food, spanish food, Thai food, indian food, via google places API on an iPhone app.
How can i do that?? As i see supported types, there is only food, restaurant, etc in it. besides whenever i use this query..
NSString *url = [NSString stringWithFormat:#"https://maps.googleapis.com/maps/api/place/search/json?location=%f,%f&radius=%#&type=restaurant&query=%#&sensor=true&key=%#", currentCentre.latitude, currentCentre.longitude, [NSString stringWithFormat:#"%i", currenDist], googleType, kGOOGLE_API_KEY];
i am getting few results only, whenever i try to add more types like food|restaurant|establishment like below query my app crashes.
NSString *url = [NSString stringWithFormat:#"https://maps.googleapis.com/maps/api/place/search/json?location=%f,%f&radius=%#&type=food|restaurant|establishment&query=%#&sensor=true&key=%#", currentCentre.latitude, currentCentre.longitude, [NSString stringWithFormat:#"%i", currenDist], googleType, kGOOGLE_API_KEY];
As i told my app crashes with this error may be i am doing something wrong with url.
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'data parameter is nil'
* First throw call stack: (0x13be022 0x200fcd6 0x1366a48 0x13669b9 0xbadfad 0x2dd2 0x13bfe42 0xaa09df 0x139294f 0x12f5b43 0x12f5424
0x12f4d84 0x12f4c9b 0x15d47d8 0x15d488a 0x17a626 0x236d 0x22d5)
terminate called throwing an exception(lldb)
Please can someone guide me with this?? i hope i cleared all my points.
Thanks & regards,
Malhaar
It appears you are trying to use the Places API Textsearch as you are using the query parameter. If this is correct make sure you are hitting the correct backend:
maps.googleapis.com/maps/api/place/textsearch/json
Also make sure you are using the correct parameter to specify types:
types=food|restaurant|establishment
I would recommend reading the documentation thoroughly and and performing a few test html requests through your browser to make sure you have the right request before plugging it into your application.
Although this is almost 7 months old, and I'm sure you've either solved it or given up on it by now, I have just had the same issue and it took some resolving. I thought I'd put the answer here to help anyone else with a similar error.
The problem I found was to do with the URL encoding not liking the | character.
The way around it I found was to:
// Create an NSString with the URL which includes the '|' characters.
NSString * urlString = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=51.189781,-114.488907&radius=6918&types=food|bar&keyword=&sensor=true&key=YOUR KEY HERE";
// Encode the URL
NSString* encodedURLString = [urlString stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
// Covert to a NSURL
NSURL *googleRequestURL=[NSURL URLWithString:encodedURLString];
And then use the googleRequestURL as the URL.
Hopefully that will solve it for you!

get route direction between two location

I have to get routing direction i.e. all the lat-long location between two location which i provide.
I know below code works for this and give js file in responce.but this code only works when two provided location are not so far. but if two location which are so far suppose between India & Australia then this would be not work and gives nothing in js file.
My code is as below.
[NSString* str1 = [NSString stringWithFormat:#"%f,%f", loc1.latitude, loc1.longitude\];
NSString* str2 = [NSString stringWithFormat:#"%f,%f", loc2.latitude, loc2.longitude\];
NSString* urlStr = [NSString stringWithFormat:#"http://maps.google.com/maps?output=dragdir&saddr=%#&daddr=%#&output=dragdir", str1, str2\];]
What should i do or I am missing any thing or any filtering is required.Please help me.
-Thanx in advance
Check out first in maps.google.com-> getdirection and check with your location it didn't response because between India and Australia there is no physical root if you check with only land joint country it given correct path so may be it possible same case in iOS..

Google maps in UIWebview shows driving directions not the map directly

I am loading google maps in UIWebview by providing the lat long co-ordinates for the Source and destination.But the problem is it shows the driving directions when it gets loaded.If we want to see the map then we have to click on the map button provided alongside the address.I need to directly show the map instead of driving directions when the web view gets loaded.
Can any one tell me how do I achieve this.
UIWebView *webView=[[UIWebView alloc]initWithFrame:webViewRect];
webView.delegate=self;
webView.scalesPageToFit=YES;
CLLocationCoordinate2D start = { 34.052222, -118.243611 };
CLLocationCoordinate2D destination = { 37.322778, -122.031944 };
//NSString *urlString=#"http://maps.google.co.in/";
NSString *googleMapsURLString = [NSString stringWithFormat:#"http://maps.google.com/?saddr=%1.6f,%1.6f&daddr=%1.6f,%1.6f",
start.latitude, start.longitude, destination.latitude, destination.longitude];
NSLog(#"URL string-----> %#",googleMapsURLString);
NSURL *url=[NSURL URLWithString:googleMapsURLString];
NSURLRequest *requestObj=[NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
[self.view addSubview:webView];
Also I would like to know how to I pass the url if i need to go from say place A to B and from B to C.
Just change your URL line
NSString *googleMapsURLString = [NSString stringWithFormat:#"http://maps.google.com/?saddr=%1.6f,%1.6f&daddr=%1.6f,%1.6f", start.latitude, start.longitude, destination.latitude, destination.longitude];
with the below code
NSString *googleMapsURLString = [NSString stringWithFormat:#"http://maps.google.com/?saddr=%1.6f,%1.6f&daddr=%1.6f,%1.6f&output=embed",start.latitude, start.longitude, destination.latitude, destination.longitude];
The only thing added is output=embed which forces the web to open the map directly without opening the screen which asks for filled input box for source and destination.
For more clarifications you can also check out all the parameters that are used in google map from Google Map Parameters
Above will solve your first query.
And regarding second query
i.e. Also I would like to know how to I pass the url if i need to go from say place A to B and from B to C.
Sorry no idea
NSString *ll = [NSString stringWithFormat:#"%f,%f",
self.placemark.location.coordinate.latitude,
self.placemark.location.coordinate.longitude];
ll = [ll stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *url = [NSString stringWithFormat:#"http://maps.google.com/?q=%#", ll];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
[self.tableView deselectRowAtIndexPath:indexPath animated:NO];
In perusing the Google Map Parameters documentation, linked above, I came across the answer to the second part of this question.
Also I would like to know how to I pass the url if i need to go from say place A to B and from B to C.
The Directions portion of the parameter space appears to allow multiple destinations to be routed in sequence by appending "+to:" clauses to the daddr component of the query arguments.
For instance:
https://maps.google.com/maps?saddr=Ferry+Plaza+SF&daddr=Coit+Tower+to:Union+Square
shows a route beginning at the Ferry Plaza in San Francisco which then goes to Coit Tower, then Union Square, in that order.
Read about the 'daddr=' parameter in the above-linked Directions section of that wiki for further info.
In general, you can figure out what Google Maps URLs should look like through parameter inspection. E.g.:
Go to maps.google.com and query for a map with the routes, destinations, etc. that you are interested in.
When you have a map that looks like what you want, click the link icon (looks like a chain) to get a copy of the URL that corresponds to the parameters you've specified.
Paste this URL into the browser address bar.
Proceed to parse out parameters from the query string to determine which parts correspond to what on the map.
Cross-reference with pages like the mapki.com link above if you aren't sure what a parameter is doing.
You should be able to deduce formulation of new kinds of queries using this process.

Google Maps Boundaries (limiting location data to a Lat/Long Boundary)

Anyone know how to get thew Google Maps API HTTP request/response to only return me Locations that fall within Australia ?
I thought I could just add:
bounds=lat, long | lat Long
Creating a square boundary based off Coordinates, but Google for some strange reason isn't liking it.
[NSString stringWithFormat:#"%#%#+Australia&bounds=-9.102097,104.765625|-44.902578,159.697266&sensor=false&region=au", kGoogleGeocodeURL, params];
Problem resolved, it turns out that the search string was correct, but I needed to use UTF8Encoding, as NSString didn't like the Commas.