How to give a location coordinate to plot a point in a map in ios using storyboard?
13,638
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];
Related videos on Youtube
Author by
chandru
Greetings..! I am a graduate in engineering, have a good knowledge in C and CPP, but totally new to Objective C. I am currently undergoing training as a iPhone App Developer.
Updated on September 16, 2022Comments
-
chandru over 1 year
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 inMapKit.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?
-
chandru over 10 yearsThree errors are displayed, use of undeclared identifier "Annotation".
-
iGagan Kumar over 10 yearsIts MKAnnotation not Annotation
-
Sukesh over 10 yearsTHE_SPAN 0.01f In the place of latitude and longitude give your value...
-
chandru over 10 yearsYa,thank u, this works perfect, can we use any icons(own Pictures) other than annotation.
-
Bhumeshwer katre over 10 yearsYou can use -(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {} this method to customize annotation.
-
chandru over 10 yearsNo, it is not working, any way thank u, but the first answer worked.
-
chandru over 10 yearsWat is that above comment
-
Sukesh over 10 yearsIn the above coding in the place of THE_SPAN give value 0.01f,and in the place of latitude and longitude give your latitude and longitude values..
-
Bhumeshwer katre over 10 yearsYou can get idea through this link blog.asolutions.com/2010/09/…
-
chandru over 10 yearsk, wat is that MapViewC
-
Sukesh over 10 yearsyou would have declared the map view in .h file. Use the same name here and try.
-
chandru over 10 yearsYa, thank u, can we plot our own pictures instead of annotation
-
Sukesh over 10 yearscheck it here stackoverflow.com/questions/9814988/…