Is it possible to take advantage of Apple's places information or even reference one using MapKit?
Didn't find anything on Location Awareness Programming Guide.
Tried matching the address details using a MKPlacemark, e.g.
MKPlacemark* placeMark = [[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:#{
(NSString *)kABPersonAddressStreetKey:#"113 Buccleuch Street",
(NSString *)kABPersonAddressCityKey:#"Edinburgh",
(NSString *)kABPersonAddressStateKey:#"UK",
(NSString *)kABPersonAddressZIPKey:#"EH8 9",
(NSString *)kABPersonAddressCountryKey:#"United Kingdom",
(NSString *)kABPersonAddressCountryCodeKey:#"GB",
}];
MKMapItem* mapItem = [[MKMapItem alloc] initWithPlacemark:placeMark];
mapItem.name = #"Coyaba";
But it seems like lat/long take precedence over address.
I think the new (iOS 6.1+) MKLocalSearch is the best fit for what you want. It will find points of interest using a natural language search pattern.
I don't think there's any way to just request all points of interest or retrieve the "clickable objects" like in the Apple Maps app. Many of the objects come from Yelp, so you could look into whether they offer an API.
Have you tried geocoding example? Download it and try it..
Related
There are problems with auto complete, to me google autocomplete search bar is filling writes all cities in the world but I need only the address of my city.
You can use the GMSCoordinateBounds, which is
A object which restrict the results to a specific area specified by latitude and longitude bounds.
In additional, There are some Location Biasing options for the JS API, but no sure if iOS API has them too.
I found information, we cant search just in city.We can minimum set search in Country. Google say - they will fix it in next version.
NSMutableString *url = [NSMutableString stringWithFormat:#"https://maps.googleapis.com/maps/api/place/autocomplete/json?input=%#&sensor=%#&components=country:%#""&key=%#",
[input stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
SPBooleanStringForBool(sensor), countryCode,key];
This worked for me:
GMSVisibleRegion visibleRegion = self.mapView.projection.visibleRegion;
GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithCoordinate:visibleRegion.farLeft coordinate:visibleRegion.nearRight];
My code is virtually identical to the following example:
https://github.com/iamamused/Example-MKLocalSearch.git
Here are the important bits:
#interface ViewController : UIViewController
#property (strong, nonatomic) IBOutlet MKMapView *ibMapView;
#end
#implementation ViewController {
MKLocalSearch *localSearch;
MKLocalSearchResponse *results;
}
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
[localSearch cancel];
MKLocalSearchRequest *request = [[MKLocalSearchRequest alloc] init];
request.naturalLanguageQuery = searchBar.text;
request.region = self.ibMapView.region;
localSearch = [[MKLocalSearch alloc] initWithRequest:request];
[localSearch startWithCompletionHandler:^(MKLocalSearchResponse *response, NSError *error){
[self.resultTable reloadData];
}
}
It seems reasonable that when Sutter and Mason aka 600 Sutter St. are inside the map region searching for "600 Sutte" would include the obvious result "600 Sutter St.". I just can't get that to work. I've tried many different streets and I often get results out of state before I get results that are directly in the map region.
Also, "600 Sut" returns irrelevant results, while "600 Su" returns an error 4. Did it really not find anything that starts with "600 Su"?
Am I using this API completely wrong or is it not meant for what I'm trying to do with it?
Map Region for all queries:
600 Sutte
600 Su
I ended up giving up on Apple local search API and switching to Google. Their Place API is exactly what I needed. It finds relevant results quickly and up to 100k requests per day doesn't cost anything.
Auto-complete:
https://developers.google.com/places/documentation/autocomplete
Details (need this for lat, lon):
https://developers.google.com/places/documentation/details
With the help of JSONModel I built it into my iOS app in a few hours.
The results are exactly what I was hoping to see:
#borisz - too few points to comment directly..BEWARE of using Google Places API in your IOS app. Google states in their terms and conditions that any map displaying data fetched from Google Places API needs to be a Google Map. So if you still wish to use their API and search, just make sure that you are also using a Google Map and not Apple's native maps. Hope this helps - goodluck!
Posting this for those who still have similar problem.
You shouldn't use MKLocalSearchRequest() instead use MKLocalSearchCompleter which gives better results and is used in current Apple Maps.
You can learn how to implement in this
answer
I am using the following code for Map turn by turn navigation for iOS 6,
Class mapItemClass = [MKMapItem class];
if (mapItemClass && [mapItemClass respondsToSelector:#selector(openMapsWithItems:launchOptions:)])
{
// Create an MKMapItem to pass to the Maps app
CLLocationCoordinate2D coordinate =
CLLocationCoordinate2DMake(16.775, -3.009);
MKPlacemark *placemark = [[MKPlacemark alloc] initWithCoordinate:coordinate
addressDictionary:nil];
MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:placemark];
[mapItem setName:#"My Place"];
// Pass the map item to the Maps app
[mapItem openInMapsWithLaunchOptions:nil];
}
It's redirecting me onto the Maps app so ,What i need,i need to open up this within my app interface so as user can remain in the app and not quit the app interface.
Please suggest some ideas to control this.
MKMapKit does not support navigation in MKMapView, you will need to send the user to map.app.
Your only option is to build the navigation your self if you really want to turn by turn navigation with in your app.
As rckoenes said, you have to implement this yourself if you don't want to launch an external app.
If you plan to do a simple version of turn-by-turn navigation, you can get the relevant data via the Google Maps Directions API:
https://developers.google.com/maps/documentation/directions/
From the JSON (or xml) response you get the driving instructions and location data for every step and waypoint. Also a string under the tag "overview_polyline" is provided here. You can draw the route directly on the map by using this string as GMSPath if your're working with the Google Maps IOS SDK.
The main challenge of a self-written navigation app is constructing a robust logic for tracking the user and providing turn-by-turn instructions accurately, as well as exception handling (e.g. losing signal in tunnels...). But just showing the route and the instructions visually should be relatively easy.
I'm working on an application that needs to detect the user's location.
I need to extract the user's country and city codes.
I was able to get the country code using a placemark in locationManager: didUpdateToLocation: fromLocation: as follows:
CLGeocoder * geoCoder = [[CLGeocoder alloc] init];
[geoCoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
MKPlacemark * mark = [[MKPlacemark alloc] initWithPlacemark:[placemarks objectAtIndex:0]];
NSString * code = mark.countryCode;
NSLog(#"country code: %#", code);
}];
So, is there any solution that helps me find an IATA 3-Letter Code for the user's city ?
I suggest you use the database available at OpenFlights: http://openflights.org/data.html (which #Ben-G linked indirectly).
There is a somewhat 'web service' as a form: http://openflights.org/html/apsearch but I think that given the size of the database (about 9200 entries) it is actually better to import it in the app and query it directly, specially if you are going to query a lot (more queries... more traffic if using a web service, and so more delay and decreased user experience, etc).
Though I wonder why you wouldn't calculate a circle given the user's position and then query the database for any airport within some specific radius. That will give you all airports in the whereabouts and obviously the cities and the country. Getting the airport code(s) given the user's city might give you nothing if the city mainly served by an airport doesn't correspond to the city of the user's location.
I'm using the iOS 6.0 SDK and I would like to route between two different addresses (not latitude and longitude) with Apple's new iOS 6.0 maps. I would like to show the indications too.
How can I do this?
I looked into do doing this last week and did not figure out a way to do it. It appears that you can give a destination, and you can sort of give it more than just coordinates, but it always assumes your starting position is the current location. That is limiting when you may be planning a trip while you are not currently at the starting location. (But perhaps I am just not seeing how it is done and I hope someone can correct me if that is true.)
A while back I looked into routing options for iOS 6 and gathered the results here...
How would you providing routing for directions between points on a map? What are the missing pieces?
You still may not be able to open up Apple Maps with the exact routing that you want, but perhaps you can draw the route with overlays and annotations on your own instance MKMapView. That may be the best you can do for now.
Below is the code that I used to route to a location and provide at least a label for the destination instead of leaving it to only coordinates. I found that simply giving the destination a label with the full address details would not work, so I just provide that one value.
if (flag != DirectionsFlag_PublicTransit && itemClass && [itemClass respondsToSelector:#selector(openMapsWithItems:launchOptions:)]) {
NSDictionary *address = #{ (NSString *)kABPersonAddressStreetKey : location.title };
MKPlacemark *destinationPlacemark = [[MKPlacemark alloc] initWithCoordinate:location.coordinate addressDictionary:address];
MKMapItem *destinationMapItem = [[MKMapItem alloc] initWithPlacemark:destinationPlacemark];
if (flag == DirectionsFlag_Driving) {
[destinationMapItem openInMapsWithLaunchOptions:#{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving}];
}
else if (flag == DirectionsFlag_Walking) {
[destinationMapItem openInMapsWithLaunchOptions:#{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeWalking}];
}
}
This code specifically does not handle Public Transit directions since Apple Maps does not do that. I instead have it open up Google Maps with the URL that I was using previously which now opens up Safari for those directions. The flag is an enum value of Driving, Walking or Public Transit. The location is a model which contains various details including title and coordinates.