Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to give a location coordinate to plot a point in a map in ios using storyboard?

I am creating a map view in a view controller, using 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];
}

A point is plotted in San Francisco, CA, United States. The userLocation coordinates are the predefined value in MapKit.h framework. Now I create a

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

Here, the region is displayed having the coordinate in the center. But, no point is plotted at the coordinate position.

How to plot a point or annotation in that coordinate location?

like image 569
chandru Avatar asked Nov 20 '13 06:11

chandru


1 Answers

Try this code inside of didUpdateUserLocation method

    MKPointAnnotation*    annotation = [[MKPointAnnotation alloc] init];
    CLLocationCoordinate2D myCoordinate;
    myCoordinate.latitude=13.04016;
    myCoordinate.longitude=80.243044;
    annotation.coordinate = myCoordinate;
    [self.mapView addAnnotation:annotation];
like image 195
Bhumeshwer katre Avatar answered Oct 28 '22 13:10

Bhumeshwer katre