1. Use the showuserlocation attribute of uimapview.
Mymapview. showsuserlocation = Yes
After the display, read the coordinates, longitude, and latitude:
Self. userlocation. Coordinate. Latitude
Self. userlocation. Coordinate. longpolling
2. Use cllocationmanager
Locationmanager = [[cllocationmanager alloc] init];
Locationmanager. Delegate = self;
Locationmanager. desiredaccuracy = kcllocationaccuracybest; // select the optimal location
[Locationmanager startupdatinglocation];
After positioning, read the longitude and latitude in the delegate method:
-(Void) locationmanager :( cllocationmanager *) Manager
Didupdatetolocation :( cllocation *) newlocation
Fromlocation :( cllocation *) oldlocation
The first two methods are to use the core location framework to locate and select the final scheme based on the GPS, cell tower, and Wi-Fi sequence:
A. GPS Positioning: The accuracy can be up to 10 m;
B. cellular base stations: The accuracy is related to the density of local base stations;
C. Wi-Fi: IP addresses are used for locating, which is inaccurate and sometimes may contain errors of several miles. The iPhone's Wi-Fi positioning uses skyhook wireless to return the geographic coordinates of the corresponding IP address. Because the company's IP address is not included in the library, the iPhone's self-contained Wi-Fi positioning cannot be used;
3. Use the location service of Firefox and Safari:
Write an HTML file, load it with mapview, and use alert to return the obtained geographic coordinate information.
<HTML>
<Head>
<Title> know your current location </title>
<SCRIPT type = "text/JavaScript" src = "json2.js"> </SCRIPT>
<SCRIPT type = "text/JavaScript">
Navigator. geolocation. getcurrentposition (getlocation, unknownlocation );
Function getlocation (POS)
{
VaR latitde = pos. coords. Latitude;
VaR longpolling = pos. coords. longpolling;
Alert (JSON. stringify ({"latitude": latitde,
"Longtitude": longpolling }));
}
Function unknownlocation ()
{
Alert ('could not find location ');
}
</SCRIPT>
</Head>
</Html>
This method can achieve Wi-Fi positioning, but it is not accurate.