How to specify the location coordinate for plotting a point on a map in ios using a storyboard?

I am creating a map view in a view controller using a storyboard.

When I use the following code.

-(void) mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation { CLLocationDistance distance = 1000; MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate, distance, distance); MKCoordinateRegion adjusted_region = [self.mapView regionThatFits:region]; [self.mapView setRegion:adjusted_region animated:YES]; } 

Point built in San Francisco, California, USA. userLocation is a predefined value in MapKit.h . Now i create

 -(void) mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation { CLLocationDistance distance = 1000; CLLocationCoordinate2D myCoordinate; myCoordinate.latitude = 13.04016; myCoordinate.longitude = 80.243044; MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(myCoordinate, distance, distance); MKCoordinateRegion adjusted_region = [self.mapView regionThatFits:region]; [self.mapView setRegion:adjusted_region animated:YES]; } 

The area with the coordinate in the center is displayed here. But there is no point in the coordinate position.

How to build a point or annotation at this coordinate location?

+8
ios mapkit
source share
3 answers

Try this code inside didUpdateUserLocation method

  MKPointAnnotation* annotation = [[MKPointAnnotation alloc] init]; CLLocationCoordinate2D myCoordinate; myCoordinate.latitude=13.04016; myCoordinate.longitude=80.243044; annotation.coordinate = myCoordinate; [self.mapView addAnnotation:annotation]; 
+9
source share

Add this code to doUpdateUserLocation file

 MKAnnotation *annotation = [[MKAnnotation alloc] initWithCoordinate:CLLocationCoordinate2DMake(latitude, longitude)]; [myMap addAnnotation:annotation]; 
0
source share

Try it. // MAP VIEW Point

 MKCoordinateRegion myRegion; //Center CLLocationCoordinate2D center; center.latitude=latitude; center.longitude=longitude; //Span MKCoordinateSpan span; span.latitudeDelta=THE_SPAN; span.longitudeDelta=THE_SPAN; myRegion.center=center; myRegion.span=span; //Set our mapView [MapViewC setRegion:myRegion animated:YES]; //Annotation //1.create coordinate for use with the annotation CLLocationCoordinate2D wimbLocation; wimbLocation.latitude=latitude; wimbLocation.longitude=longitude; Annotation * myAnnotation= [Annotation alloc]; myAnnotation.coordinate=wimbLocation; 
0
source share

All Articles