IOS development: Display your location on Google Maps

Source: Internet
Author: User

One rowCodeShow your location

Mapkit in IOS integrates the positioning function. You can use a line of code to display your current location on Google map. The Code is as follows:

 
-(Ibaction) showlocation :( ID) sender {If ([btnshowlocation titleforstate: uicontrolstatenormal] isequaltostring: @ "show my location"]) {[btnshowlocation settitle: @ "hide my location" forstate: uicontrolstatenormal]; mapview. showsuserlocation = yes;} else {[btnshowlocation settitle: @ "show my location" forstate: uicontrolstatenormal]; mapview. showsuserlocation = no ;}}

The key code is mapview. showuserlocation = yes.

Use cllocationmanager and mkmapview In addition, the corelocation framework writes code to request the current location, which is also very simple: Step 1: Create a cllocationmanager instance
 
Cllocationmanager * locationmanager = [[cllocationmanager alloc] init];
Step 2: Set the cllocationmanager instance delegation and precision
 
Locationmanager. Delegate = self; locationmanager. desiredaccuracy = kcllocationaccuracybest;
Step 3: Set the distance filter distancefilter. The following indicates that the device must be at least 1000 meters moved before the delegated update is notified.
 
Locationmanager. distancefilter = 1000.0f;
Or the default settings without filters are as follows:
 
Locationmanager. distancefilter = kcldistancefilternone;
Step 4: Start the request
 
[Locationmanager startupdatinglocation];
Use the following code to stop a request:
 
[Locationmanager stopupdatinglocation];
The cllocationmanagerdelegate delegate includes the locationmanager: didupdatetolocation: fromlocation method to obtain the longitude and latitude. You can use the following code to obtain the longitude and latitude from the cllocation instance:
Cllocationdegrees latitude = thelocation. Coordinate. Latitude; cllocationdegrees longpolling = thelocation. Coordinate. longpolling;
Use the following code to obtain your altitude:
 
Cllocationdistance altitude = thelocation. altitude;
Use the following code to obtain your displacement: Cllocationdistance distance = [Fromlocation distancefromlocation: tolocation];

Summary:This article mainly explains how to display your current location on the iOS device Google map.

Related Article

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.