i want search destination using name in mapkit , longitude , latitude (cllocationcoordinate2d).
currently i'm using hardcoded value set destination.
// make directions request mkdirectionsrequest *directionsrequest = [mkdirectionsrequest new]; // start @ our current location mkmapitem *source = [mkmapitem mapitemforcurrentlocation]; [directionsrequest setsource:source]; // make destination --> want coordinate using name cllocationcoordinate2d destinationcoords = cllocationcoordinate2dmake(45.545824, 9.327515); mkplacemark *destinationplacemark = [[mkplacemark alloc] initwithcoordinate:destinationcoords addressdictionary:nil]; mkmapitem *destination = [[mkmapitem alloc] initwithplacemark:destinationplacemark]; [directionsrequest setdestination:destination];
you have use clgeocoder forward-geocode using address:
clgeocoder *geocoder = [[clgeocoder alloc] init]; [geocoder geocodeaddressstring:@"new york city" completionhandler:^(nsarray *placemarks, nserror *error) { if (error) { nslog(@"%@", error); } else { clplacemark *placemark = [placemarks lastobject]; mkcoordinateregion region; region.center.latitude = placemark.location.coordinate.latitude; region.center.longitude = placemark.location.coordinate.longitude; [self.mapview setregion:region animated:yes]; } }];
this set map's region location returned, using latitude , longitude it's centre.