IOS translation into detailed positions based on latitude and longitude

Source: Internet
Author: User

First, Apple obtains the longitude and latitude

[Plain]
If ([CLLocationManager locationServicesEnabled]) {// determines whether the mobile phone can be located.
LocationManager = [[CLLocationManager alloc] init]; // initialize the Location Manager
[LocationManager setDelegate: self];
[LocationManager setDesiredAccuracy: kCLLocationAccuracyBest]; // sets the precision.
LocationManager. distanceFilter = 1000.0f; // you can specify a distance filter.
[LocationManager startUpdatingLocation]; // start Location Manager
}
Then obtain the longitude and latitude according to the proxy
[Plain]
# Pragma mark-CLLocationManager Delegate Methods
-(Void) locationManager :( CLLocationManager *) manager
DidUpdateToLocation :( CLLocation *) newLocation
FromLocation :( CLLocation *) oldLocation;
{
Location = [newLocation coordinate]; // The current latitude and longitude
Lat = location. latitude;
Lon = location. longpolling;

MKCoordinateSpan theSpan;
TheSpan. latitudeDelta = 0.01f;
TheSpan. longitudeDelta = 0.01f;
TheRegion. center = location; // defines the map display range
TheRegion. span = theSpan;
}
There are currently two types of resolution based on longitude and latitude. The first is to call the reverseGeocodeLocation method of the CLGeocoder class of the system.
[Plain]
// Parses the data into a location based on the longitude and latitude.
CLGeocoder * geocoder = [[CLGeocoder alloc] init] autorelder];
[Geocoder reverseGeocodeLocation: location completionHandler: ^ (NSArray * placemark, NSError * error)
{
CLPlacemark * mark = [placemark objectAtIndex: 0];
Place. title = @ "no details of the current location ";
Place. subTitle = @ "For details, click nearby to View Details ";
Place. title = [NSString stringWithFormat: @ "% @", mark. subLocality, mark. thoroughfare, mark. subThoroughfare];
Place. subTitle = [NSString stringWithFormat: @ "% @", mark. name]; // obtain the subtitle Information
[Self. myMapView selectAnnotation: place animated: YES];
}];
The second is to call google's api
---- Http://maps.googleapis.com/maps/api/geocode/json? Latlng = % f, % f & sensor = true

Some people on the Internet say that the system method sometimes cannot parse the location. The second kind of google, sometimes unable to access the google server in China, has its disadvantages.

Someone suggested that AMAP can be used for domestic maps (I will try again later)

PS1: There is a popular nearby search function on the Internet, which is based on google's api Search


# Define SEARCH_GOOGLE @ "https://maps.googleapis.com/maps/api/place/search/json? Location = % f, % f & radius = 1000 & types =%@ & sensor = true & key = aizasyalaqx0mfpsp2aldbzbzeqaq64swg1_z0c"

The call is like this.
JsonString = [NSString stringWithFormat: SEARCH_GOOGLE, location. coordinate. latitude, location. coordinate. longpolling, @ "food"];
JsonString = [NSString stringWithFormat: SEARCH_GOOGLE, location. coordinate. latitude, location. coordinate. longpolling, @ "bus_station"];
JsonString = [NSString stringWithFormat: SEARCH_GOOGLE, location. coordinate. latitude, location. coordinate. longpolling, @ "hospital"];

PS2: There is a function. If you hold down a certain place on the map for a long time, how can you obtain its latitude and longitude and display its position?
----
[Plain]
// Start to click long press, otherwise it will be executed twice.
If (sender. state = UIGestureRecognizerStateBegan ){
// IsLongPress = YES;
CGPoint touchPoint = [sender locationInView: self. myMapView];
CLLocationCoordinate2D touchCoordinate = [self. myMapView convertPoint: touchPoint toCoordinateFromView: self. myMapView]; // converts the touch point to the longitude and latitude.
// Reverse resolution of PIN information with long time
Location = [[CLLocation alloc] initWithLatitude: touchCoordinate. latitude longpolling: touchCoordinate. longpolling];

 


 

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.