IPhone application map development tutorial

Source: Internet
Author: User

IPhoneApplicationMap DevelopmentThe tutorial is the content to be introduced in this article, which describes an interesting example. Not to mention, let's take a look at the details.

1. Calculate the distance between two points

 
  1. [LocationManager startUpdatingLocation]; formatted as 12.34 ):
  2. [NSString stringWithFormat: @ "% 0.2f km", [userLocation getDistanceFrom: location]/1000]

2. When processing the MKAnnotationView, you must determine whether the corresponding annotation is MKUserLocation, the blue point that shows the user's current location, to avoid misoperation.

 
  1. [annotation isKindOfClass:[MKUserLocation class]]  

3,

 
  1. - (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation 

This delegate function is generally executed immediately after annotations are added to the MKMapView object, but the execution will not end immediately. If you call

 
  1. [mapView viewForAnnotation:someAnnotation]; 

Then, the nil result will be returned, and any operations on the returned nil will not be displayed on the screen ......

4. When the MKMapView is zoomed in and out, you must note that the MKMapView is zoomed in at least two times.

 
  1. -(IBAction) doZoomIn :( id) sender {// enlarge
  2. MKCoordinateRegion region = mMapView. region;
  3. Regionregion. span. latitudeDelta = region. span. latitudeDelta * 0.4;
  4. Regionregion. span. longitudeDelta = region. span. longitudeDelta * 0.4;
  5. [MapView setRegion: region animated: YES];
  6. }
  7. -(IBAction) doZoomOut :( id) sender {// zoom out
  8. MKCoordinateRegion region = mMapView. region;
  9. Regionregion. span. latitudeDelta = region. span. latitudeDelta * 1.3;
  10. Regionregion. span. longitudeDelta = region. span. longitudeDelta * 1.3;
  11. [MapView setRegion: region animated: YES];
  12. }

5. Below are some other codes not mentioned for search engines.

 
  1. CLLocationCoordinate2D coordinate;   
  2. //Location Paris   
  3. coordinate.latitude = 48.856660;   
  4. coordinate.longitude = 2.350996;   
  5. MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(coordinate, distance, distance);   
  6. MKCoordinateRegion adjustedRegion = [mapView regionThatFits:viewRegion];   
  7. [mapView setRegion:adjustedRegion animated:animated];  

6. Question:

A bug was found in the Callout View of MKAnnotationView.

After I update the subtitle in the background, if I do not manually click another MKAnnotationView and then click back to the MKAnnotationView that has previously shown Calloutview, the subtitle in the Calloutview of this MKAnnotationView will not be updated ......

Clearly, after you click a pin to display information, if the background updates its subtitle, then you click the pin to find that its subtitle is blank. Click another pin and then click back. The information of the pin is complete.

Although one notification is MKAnnotationCalloutInfoDidChangeNotification, the SDK manual says this is no longer usable. I tried it and it didn't work ......
I don't know if there are other methods.

Summary:IPhoneApplicationMap DevelopmentI hope this article will help you with the introduction of this tutorial!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.