iOS Google maps giving error - ios

In my App it is possible to tap an button and then in the Google maps app it shows the route from your current location to the destination. It was working till some internal data structures changed and now it is not ;)
The error I get is:
Error Domain=kCLErrorDomain Code=8 "The operation couldn’t be completed. (kCLErrorDomain error 8.)"
Which I looked up in the documentation means (I think):
kCLErrorGeocodeFoundNoResult
The geocode request yielded no result.
Available in iOS 5.0 and later.
Declared in CLError.h.
Currently this is my code: (I'm using hardcoded location for testing right now):
+ (void) showRouteInMapsFromCurrentToLocation:(NSString *) location{
Class mapItemClass = [MKMapItem class];
if (mapItemClass && [mapItemClass respondsToSelector:#selector(openMapsWithItems:launchOptions:)]){
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:#"Kardingerweg 48, Groningen"
completionHandler:^(NSArray *placemarks, NSError *error) {
if(!error){
CLPlacemark *geocodedPlacemark = [placemarks objectAtIndex:0];
MKPlacemark *placemark = [[MKPlacemark alloc]
initWithCoordinate:geocodedPlacemark.location.coordinate
addressDictionary:geocodedPlacemark.addressDictionary];
if(placemark && geocodedPlacemark){
MKMapItem *mapItem = [[MKMapItem alloc] initWithPlacemark:placemark];
[mapItem setName:geocodedPlacemark.name];
NSDictionary *launchOptions = #{MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeDriving};
MKMapItem *currentLocationMapItem = [MKMapItem mapItemForCurrentLocation];
[MKMapItem openMapsWithItems:#[currentLocationMapItem, mapItem] launchOptions:launchOptions];
}
}else{
NSLog(#"%#", [error description]);
}
}];
}
}

Error Code 8 is "kCLErrorGeocodeFoundNoResult", so I suspect you're searching for something with no results,
You are searching for 'Kardingerweg 48, Groningen' it is also not searching in apple map, try with different location.'Kardingerweg,Groningen'.

Thanks to the answer of Viruss mca, I now have the correct form which is:
Kardingerweg 48, NL-2165 VS Groningen

Related

how to get exact coordinates of given address using forward geocoding

In my application I want the exact lattitude and longitude of given address using forward geocoding in IOS in Objective-C.
I had used forward geocoding in my application but it is not giving the exact address. this is my code of forward geocoding
-(void)detectlocation:(NSString*)address
{
CLGeocoder *geocoder=[[CLGeocoder alloc]init];
[geocoder geocodeAddressString:address completionHandler:^(NSArray *placemarks, NSError *error)
{
if(!error)
{
CLPlacemark *placemark = [placemarks objectAtIndex:0];
NSLog(#"%f",placemark.location.coordinate.latitude);
NSLog(#"%f",placemark.location.coordinate.longitude);
self.latitude4=placemark.location.coordinate.latitude;
self.longitude4=placemark.location.coordinate.longitude;
NSLog(#"%#",[NSString stringWithFormat:#"%#",[placemark description]]);
}
}];
}
Thanks In Advance
You can access placemark properties for a more accurate location.
This is swift, but the same is for objective-c
Declare and initiate your CLLocationMager* inside the viewDidLoad method.
I recommend to use:
#property YourCustomLocation* foundedLocation;
in order to "save" data of the place that has been found.
Then try this inside your method:
[self.geocoder geocodeAddressString:address completionHandler:^(NSArray *placemarks, NSError *error) {
//if 1+ "places" have been found:
if ([placemarks count] > 0) {
//save the first place that has been found
CLPlacemark *placemark = [placemarks objectAtIndex:0];
//save location from the placemark
CLLocation *location = placemark.location;
//save coordinates from location
CLLocationCoordinate2D coordinate = location.coordinate;
//Do more stuffs...like:
self->_foundedLocation = [[YouCustomLocation alloc]initLocationWithLatitude:coordinate.latitude Longitude:coordinate.longitude];}
}];
Remember that forward-geocoding works with blocks, so unless you use __block directive near the variable you won't be able to "save the location" on a variable declared outside the block.

What is the replacement for getFromLocationName() for IOS?

I have implemented google map on IOS, now i want to locate marker on some company brand name, before i have experience of implementing in Android.
In Android getFromLocationName() to get the address info like lat, long from geocoder but I am not getting any in build function like this in IOS?
any help?
i think its giving you error because, geocoder is not able to find the location.
check this code ,
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:#"Palolem Beach, Goa, India" completionHandler:^(NSArray* placemarks, NSError* error){
if (!error) {
for (CLPlacemark* aPlacemark in placemarks)
{
NSLog(#"place--%#", [aPlacemark locality]);
NSLog(#"lat--%f\nlong--%f",aPlacemark.location.coordinate.latitude,aPlacemark.location.coordinate.longitude);
}
}
else{
NSLog(#"error--%#",[error localizedDescription]);
}
}];

How to add annotation manually to map view in iOS?

I'd like to add annotation manually (when user touch in to the particular place in map view) and to get the details of that location (latitude,longitude,address)..
as #iPrabu directed to similar post, with very good and correct answer for your problem... for second part i.e. to get details about that location..you can do something like this
-(void)getAddressFromCurruntLocation:(CLLocation *)location{
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error)
{
if(placemarks && placemarks.count > 0)
{
CLPlacemark *placemark= [placemarks objectAtIndex:0];
NSString *address = [NSString stringWithFormat:#"%# %#",[placemark country],[placemark administrativeArea]];
// you may also get locality,sublocality,subadministrativeare etc
NSLog(#"The Address Is:%#",address);
}
}];
}
Happy Coding :)

IOS/MapKit: Launch Native Map App by Clicking on MKPlacemark

IOS newb just learning Mapkit. I load a map in my app using MKPlacemark. However some users may want to use more advanced features such as driving directions and for this, I think, they would be better off launching the native app on top of mine (with my app still open in the background when they finish with the regular map app)
I know how to launch the native app from my app using MKMapItem. However, s there a way to launch the native app only after the user touches the place mark.
Here is code I am using.
-(void) geoCodeAndMapIt {
NSString* location = #"156 University Ave, Palo Alto, CA 94301";
NSLog(#"going to map this address: %#",location);
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:location
completionHandler:^(NSArray* placemarks, NSError* error){
if (placemarks && placemarks.count > 0) {
CLPlacemark *topResult = [placemarks objectAtIndex:0];
MKPlacemark *placemark = [[MKPlacemark alloc]
initWithPlacemark:topResult];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(placemark.coordinate, 5000, 5000);//5000 is meters
region.span.longitudeDelta /= 8.0;
region.span.latitudeDelta /= 8.0;
[self.mapView setRegion:region animated:YES];
[self.mapView addAnnotation:placemark];
// The following MKMapItem class launches the full blown native app. Commenting it out causes the map to load in the app. Otherwise, it fires up the native map app immediately in place of the previous app.
MKMapItem *mapItem = [[MKMapItem alloc]initWithPlacemark:placemark];
mapItem.name = self.contact.first;
mapItem.phoneNumber = self.contact.tel;
NSDictionary *options = #{
MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving,
MKLaunchOptionsMapTypeKey:
[NSNumber numberWithInteger:MKMapTypeSatellite],
MKLaunchOptionsShowsTrafficKey:#YES
};
[mapItem setName:#"Name of your location"];
[mapItem openInMapsWithLaunchOptions:options];*/
}
}
];
[mapItem openInMapsWithLaunchOptions:options];
}
Thanks for any suggestions.
You should call the openInMaps only when the MKMapViewDelegate is called on didSelectAnnotation: for ex.
https://developer.apple.com/library/ios/documentation/MapKit/Reference/MKMapViewDelegate_Protocol/index.html#//apple_ref/occ/intf/MKMapViewDelegate
To open the Maps app you could also build the URL yourself with the following:
UIApplication.sharedApplication().openURL(...)
Check this documentation here for the rest:
https://developer.apple.com/library/ios/featuredarticles/iPhoneURLScheme_Reference/MapLinks/MapLinks.html

When use ResreverseGeocodeLocation of CLGeocoder but the returned placemarks is nil and the kCLErrorDomain error =8

I want to get the location by the CLLocationCoordinate2D and I used the following code
//newLocation is a CLLocationCoordinate2D object
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder reverseGeocodeLocation:newLocation completionHandler:
^(NSArray *placemarks, NSError *error){
CLPlacemark *placemark = [placemarks objectAtIndex:0];
self.locationInput.text =placemark.subLocality;
self.locationInput.text =placemark.ISOcountryCode;
}];
but the returned placemarks is nil and the error description is kCLErrorDomain error =8
The return values are documented here.
https://developer.apple.com/library/ios/#documentation/CoreLocation/Reference/CoreLocationConstantsRef/Reference/reference.html#//apple_ref/doc/uid/TP40010237-CH2-SW2
Number 8 is "kCLErrorGeocodeFoundNoResult", so I suspect you're searching for something with no results. I've read elsewhere that CLGeocoder only runs on a device (not the simulator) but I haven't verified it myself. If you are sure your search string should get results, try your code on a device.
My issue was that I was using a VPN connected to a Thai server, trying to do a reverseGeocodeLocation on a UK postcode.
When I switched the VPN to a UK server it worked fine.

Resources