/*** Obtain the current location based on the base station */Public void getcurrentlocationagps () {telephonymanager tmanager = (telephonymanager) context. getsystemservice (context. telephony_service); If (tmanager. getcelllocation () = NULL) {return;} gsmcelllocation GCL = (gsmcelllocation) tmanager. getcelllocation (); int cid = GCL. getcid (); int LAC = GCL. getlac (); string cursor = tmanager. getnetworkoperator (); int MCC = 0; int MNC = 0; If (! Invalid. equals ("") {MCC = integer. valueof (outputs. substring (0, 3); MNC = integer. valueof (outputs. substring (3, 5);} Try {// assemble JSON query string jsonobject holder = new jsonobject (); holder. put ("version", "1.1.0"); holder. put ("host", "maps.google.com"); // holder. put ("address_language", "zh_cn"); holder. put ("request_address", true); jsonarray array = new jsonarray (); jsonobject DATA = new jsonobject (); data. put ("cell_id", CID); // 25070data. put ("location_area_code", LAC); // 4474data. put ("mobile_country_code", MCC); // 460data. put ("mobile_network_code", MNC); // 0array. put (data); holder. put ("cell_towers", array); // create a connection, send a request and accept the response defaulthttpclient client = new defaulthttpclient (); httppost post = new httppost ("http://www.google.com/loc/json "); stringentity Se = new stringentity (holder. tostring (); Post. setentity (SE); httprespon Se resp = client.exe cute (post); httpentity entity = resp. getentity (); bufferedreader BR = new bufferedreader (New inputstreamreader (entity. getcontent (); stringbuffer resultstr = new stringbuffer (); string Readline = NULL; while (Readline = BR. readline ())! = NULL) {resultstr. append (Readline);} jsonobject jsonresult = new jsonobject (resultstr. tostring (); jsonobject jsonlocation = jsonresult. getjsonobject ("location"); double jsonlat = jsonlocation. getdouble ("latitude"); double jsonlon = jsonlocation. getdouble ("longpolling"); location = new location ("agps"); location. setlatitude (jsonlat); location. setlongpolling (jsonlon);} catch (exception e) {log. I ("life", "location get failed ");}}
* Obtain the current location * @ Param context */Public void getcurrentlocationwifi (context) {wifimanager = (wifimanager) Context Based on WiFi. getsystemservice (context. wifi_service); If (wifimanager. iswifienabled () {location = lmanager. getlastknownlocation (locationmanager. network_provider );}}
/*** Obtain the current location based on GPS */Public void getcurrentlocationgps () {string locationprovider = locationmanager. gps_provider; location = lmanager. getlastknownlocation (locationprovider );}