Android positioning generally has four methods, these four ways are: GPS positioning, WiFi Dingzhun, base station positioning, AGPS positioning,
  &NBSP
(1) Android GPS: Requires GPS hardware support, direct and satellite interaction to obtain the current latitude and longitude, this way requires mobile phone support GPS module (now most of the smart machines should have). The accuracy of GPS is the highest, but its shortcomings are also very obvious: 1, compare power consumption; 2, the majority of users do not open the GPS module by default, 3, from the GPS module to obtain the first location data, it may take a long time; 4, the room is almost unusable. Among them, the shortcoming 2,3 all is more fatal. It should be pointed out that the GPS is going to the satellite communication channel, in the absence of network connectivity can also be used.
           &NBSP
To use the GPS device of the Adnroid platform, you need to add permissions first, So you need to add the following permissions:  &NBSP
               &NBSP
Uses-permission android:name= Android.permission.ACCESS_FINE_LOCATION /uses-permission
The specific implementation code is as follows:
First determine whether the GPS module exists or is open:
Private Voidopengpssettings () {
Locationmanager alm = (Locationmanager) this
. Getsystemservice ( Context.location_service);
if (ALM
. isproviderenabled (Android.location.LocationManager.GPS_PROVIDER)) {
Toast.maketext (this, the GPS module is normal , Toast.length_short)
. Show ();
return;
}
Toast.maketext (this, please open gps! , Toast.length_short). Show ();
Intent Intent = newintent (settings.action_security_settings);
Startactivityforresult (intent,0); This is returned to the Get interface when the setting is complete
}
If it is turned on, it will go directly to the display page, and if it does not, it will go to the GPS Settings page:
Get the code as follows:
Private Voidgetlocation () {//Get Position Management Service Locationmanager Locationmanager;
String serviceName = Context.location_service;
Locationmanager = (Locationmanager) this.getsystemservice (serviceName);
Find a service information criteria criteria = new criteria (); Criteria.setaccuracy (Criteria.accuracy_fine);
High precision criteria.setaltituderequired (false);
Criteria.setbearingrequired (FALSE);
Criteria.setcostallowed (TRUE); Criteria.setpowerrequirement (Criteria.power_low); Low power String provider =locationmanager.getbestprovider (criteria, true); Obtain GPS information Location Location =locationmanager.getlastknownlocation (provider);
Acquiring position updatetonewlocation (location) via GPS; Set Monitor *, the minimum time of automatic update is interval n seconds (1 seconds for 1*1000, this write is mainly for convenience) or minimum displacement change over N m locationmanager.requestlocationupdates (provider,100 * 1000, Locationlistener); }
Here you can get the location information, but still show it, then use the following method to display:
Code
Private Voidupdatetonewlocation (Location Location) {
TextView tv1;
TV1 = (TextView) This.findviewbyid (R.ID.TV1);
if (location!= null) {
double latitude = location.getlatitude ();
Double Longitude=location.getlongitude ();
Tv1.settext (dimension: + latitude+ \ Longitude +longitude);
} else {
Tv1.settext (unable to get geographic information);
}
(2) Android base station positioning: Android Base station positioning as long as you understand the base station/wifi positioning principle, it is not difficult to achieve the base station/wifi positioning. Base station location is generally several, the first is to use the mobile phone near the three base stations for triangulation, since the position of each base station is fixed, it takes time to calculate the coordinates of the mobile phone by using electromagnetic wave to transfer between the three base stations; the second is to use the information from the nearest base station, including the base station ID, Location area code, mobile country Code, mobile network code, and signal strength, send the data to Google's location-based Web service, where it can get the current location information, usually within dozens of meters to hundreds of meters. Where the signal strength of this data is important,
Here I do not explain more, directly to give an article, this article is written very well,
Http://www.jb51.net/article/34522.htm
(3) Android WiFi location: According to a fixed wifimac address, through the location of the WiFi hotspot collected, and then access to the network location services to obtain latitude and longitude coordinates. Because it and the base station localization actually all need to use the network, therefore in the Android also collectively is the network way.
Code:
public Classwifiinfomanager implements Serializable {private static final Lon
G serialversionuid= -4582739827003032383l;
private context;
Public Wifiinfomanager {super ();
This.context = context; Wifiinfo Getwifiinfo () {Wifimanager manager = (wifimanager) context. Getsyst
Emservice (Context.wifi_service);
Wifiinfo info = new Wifiinfo ();
Info.mac =manager.getconnectioninfo (). Getbssid ();
LOG.I (TAG, WIFI macis: + Info.mac);
return info;
public class Wifiinfo {public String mac;
Public Wifiinfo () {super (); }
}
}
The above is the way to get WiFi MAC address, the following is to send the address to Google Server, the code is as follows
Public staticlocation getwifilocation (Wifiinfo WiFi) {if (WiFi = null) {LOG.I (TAG, Wifiis Null.
);
return null;
} defaulthttpclient client = Newdefaulthttpclient ();
HttpPost post = new HttpPost (Http://www.google.com/loc/json);
Jsonobject holder = new Jsonobject ();
try {holder.put (version, 1.1.0);
Holder.put (host, maps.google.com);
Jsonobject data;
Jsonarray array = new Jsonarray ();
if (Wifi.mac!= null Wifi.mac.trim (). Length () 0) {data = new jsonobject ();
Data.put (mac_address, Wifi.mac);
Data.put (Signal_strength, 8);
Data.put (age, 0);
Array.put (data);
} holder.put (wifi_towers, array);
LOG.I (TAG, request JSON: + holder.tostring ()); Stringentity SE = newstringentity (Holder.tostring ());
Post.setentity (SE);
HttpResponse resp =client.execute (POST);
int State =resp.getstatusline (). Getstatuscode ();
if (state = = HTTPSTATUS.SC_OK) {httpentity entity =resp.getentity (); if (entity!= null) {BufferedReader BR = Newbufferedreader (Newinputstreamreader (
Entity.getcontent ()));
StringBuffer sb = Newstringbuffer ();
String Resute =;
while ((Resute =br.readline ())!= null) {sb.append (Resute);
} br.close ();
LOG.I (TAG, Response json: + sb.tostring ());
data = Newjsonobject (sb.tostring ());
data = (jsonobject) data.get (location);
Location loc = NewLocation (Android.location.LocationManager.NETWORK_PROVIDER); Loc.setlAtitude ((Double) data.get (latitude));
Loc.setlongitude ((Double) data.get (longitude));
Loc.setaccuracy (Float.parsefloat (data.get (accuracy). ToString ()));
Loc.settime (System.currenttimemillis ());
Return LOC;
else {return null;
} else {log.v (TAG, state +);
return null;
The catch (Exception e) {log.e (TAG, E.getmessage ());
return null;
}
}
(3.1) and the combination of WiFi positioning and base station positioning, the author also found a good article on the Internet, the author of this does not make any explanation, directly to the Web site:
Http://www.jb51.net/article/52673.htm
4. aGPS Positioning
The
AGPS (ASSISTEDGPS: Auxiliary Global Positioning System) is a combination of GSM or GPRS with traditional satellite positioning, the use of Base station to send auxiliary satellite information to reduce the GPS chip acquisition satellite signal delay time, the covered room can also borrow base station signal to make up, Reduce the reliance of GPS chips on satellites. Compared with pure GPS and base-station triangulation, AGPS can provide a wide range, more energy-saving, faster positioning services, the ideal error range within 10 meters, Japan and the United States have matured the use of aGPS in lbs service (Location Based service, location-based services). aGPS technology is a kind of technology which combines network base station information and GPS information to locate mobile station, which can be used in Gsm/gprs, WCDMA and CDMA2000 networks. The technology needs to increase the GPS receiver module in the mobile phone, and transform the mobile phone antenna, at the same time in the mobile network to add location servers, differential GPS reference stations and other equipment. The advantages of AGPS solution are mainly embodied in its positioning accuracy, in outdoor and other open areas, its accuracy in the normal GPS working environment, can reach about 10 meters, is the highest positioning accuracy of a positioning technology. Another advantage of this technique is that the first time you capture a GPS signal takes only a few seconds, unlike the first time GPS capture can take 2-3 minutes.