Poor mans GPS - Cell(Tower)ID / Location Area Code -Lookup

Tutorials that use the MapActivity. Many using GPS functionality.

Postby zehunter » Tue Mar 30, 2010 9:31 pm

estebanuri wrote:That's right, I didn't see the right class API.

http://developer.android.com/reference/android/telephony/TelephonyManager.html

public List<NeighboringCellInfo> getNeighboringCellInfo ()

Since: API Level 3
Returns the neighboring cell information of the device.
Returns
List of NeighboringCellInfo or null if info unavailable.
Requires Permission: (@link android.Manifest.permission#ACCESS_COARSE_UPDATES}

Thank you delta_foxtrot!

PS: It is remarkable that implements it, other platforms such as Blackberry does not include it in their API.


hi can any one explain to me the difference between this tutorial method (hidden api) and telephone manager ?
is their a way to detect that GPS is not running good (indoor for example) and find position from GSM network?
thanks i advance,
regards,
zehunter
Developer
Developer
 
Posts: 27
Joined: Sun Jan 10, 2010 10:45 am

Top

Postby sapiezynski » Wed Apr 21, 2010 3:36 pm

@zehunter
The problem is, that the TelephonyManager itself will not provide you with the location. It gives you all the information you need to ask Google for the location (mcc, mnc, cid and lac).

And here comes my question: Does this api still work? I am developing for Android 2.1 and had to change the implementation of plusminus but now I am getting the error code 1 instead of 0 and the message does not containg the location data. Has anybody solved this problem yet?

TIA!
Piotr
sapiezynski
Freshman
Freshman
 
Posts: 5
Joined: Wed Apr 21, 2010 3:31 pm

Postby sapiezynski » Thu Apr 29, 2010 1:45 pm

Ok, problem solved.
Instead of using the solution proposed by Plusminus now it is better to use new, official Google API for localisation:
http://code.google.com/intl/pl/apis/gea ... tocol.html

It works much better, because it does the triangulation itself as well as uses the wifi networks to locate the user.

Have fun!
sapiezynski
Freshman
Freshman
 
Posts: 5
Joined: Wed Apr 21, 2010 3:31 pm

Postby sapiezynski » Tue May 04, 2010 1:26 pm

Hi,
I recieved some questions about the API, so I will post an answer here. Sorry for not providing the full code, but my contract does not allow me to do so ;)

To use the Gears API you need to construct a JSON query and it goes like this:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. JSONObject query = new JSONObject();
  3.  
  4. try {
  5.  
  6.         query.put("version", "1.1.0");
  7.  
  8.         query.put("host", "maps.google.com");
  9.  
  10.         query.put("home_mobile_country_code", mcc);
  11.  
  12.         query.put("home_mobile_network_code", mnc);
  13.  
  14.         query.put("carrier", tm.getNetworkOperatorName());
  15.  
  16.         query.put("request_address", true);
  17.  
  18.         query.put("address_language", "en_GB");
  19.  
  20. }
  21.  
  22.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4

The above works as a header. Then you need to add the cell information. The neighboring cell information you can get from TelephonyManager (getNeighboringCellInfo()). You should add this info to the query:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. for (NeighboringCellInfo cellInfo : cellList) {
  3.  
  4.         JSONObject tower = new JSONObject();
  5.  
  6.         try {
  7.  
  8.                 tower.put("cell_id", cellInfo.getCid());
  9.  
  10.                 tower.put("location_area_code", cellInfo.getLac());
  11.  
  12.                 tower.put("mobile_country_code", mcc);
  13.  
  14.                 tower.put("mobile_network_code", mnc);
  15.  
  16.                 tower.put("signal_strength", -113 + 2*cellInfo.getRssi());     
  17.  
  18.                 query.accumulate("cell_towers", tower);
  19.  
  20.         }
  21.  
  22. }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


Then you add the WiFi information from the WifiManager.getScanResults()
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. JSONObject wifitower = new JSONObject();
  3.  
  4. try {
  5.  
  6.         wifitower.put("mac_address", result.BSSID);
  7.  
  8.         wifitower.put("signal_strength", result.level);
  9.  
  10.         query.accumulate("wifi_towers", wifitower);
  11.  
  12.  
  13.  
  14. }
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


Then you need to post it using httpPost:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.         private class Poster {
  3.  
  4.  
  5.  
  6.                 public String post(JSONObject query) {
  7.  
  8.                         Log.d(TAG, "Entering the Poster.post");
  9.  
  10.                         // TODO Auto-generated method stub
  11.  
  12.                         DefaultHttpClient httpClient = new DefaultHttpClient();
  13.  
  14.                         ResponseHandler <String> responseHandler = new BasicResponseHandler();
  15.  
  16.                         String response = null;
  17.  
  18.                        
  19.  
  20.                         HttpPost postMethod = new HttpPost("https://www.google.com/loc/json");
  21.  
  22.                         try {
  23.  
  24.                                 postMethod.setEntity(new StringEntity(query.toString()));
  25.  
  26.                         } catch (UnsupportedEncodingException e) {
  27.  
  28.                                 // TODO Auto-generated catch block
  29.  
  30.                                 Log.e(TAG, "Exception while creating entity: " + e.getMessage());
  31.  
  32.                         }
  33.  
  34.                         postMethod.setHeader("Accept", "application/json");
  35.  
  36.                         postMethod.setHeader("Content-type", "application/json");
  37.  
  38.                        
  39.  
  40.                         try {
  41.  
  42.                                 response = httpClient.execute(postMethod, responseHandler);
  43.  
  44.                                 Log.d(TAG, "response: " + response);
  45.  
  46.                         } catch (ClientProtocolException e) {
  47.  
  48.                                 // TODO Auto-generated catch block
  49.  
  50.                                 Log.e(TAG, "ClientProtocol exception while executing: " + e.getMessage());
  51.  
  52.                         } catch (IOException e) {
  53.  
  54.                                 // TODO Auto-generated catch block
  55.  
  56.                                 Log.e(TAG, "IOException while executing post: " + e.getMessage());
  57.  
  58.                         }
  59.  
  60.                        
  61.  
  62.                         return response;
  63.  
  64.                 }
  65.  
  66.                
  67.  
  68.         }
Parsed in 0.041 seconds, using GeSHi 1.0.8.4

Then you can read the response using JSONTokener:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. JSONTokener jsontokener= new JSONTokener(response);
  2.  
  3.                         jsontokener.skipPast("latitude\":");
  4.  
  5.                         String o = jsontokener.nextValue().toString();
  6.  
  7.                         String value = new String(o.getBytes(), 0, o.length() -1);
  8.  
  9.                         Log.i(TAG, "Next value: " + value);
  10.  
  11.                         double lat = Double.parseDouble(value);
Parsed in 0.037 seconds, using GeSHi 1.0.8.4

and so on. Hope that helps!
Cheers,
Piotr
sapiezynski
Freshman
Freshman
 
Posts: 5
Joined: Wed Apr 21, 2010 3:31 pm

Postby Squallco » Tue May 04, 2010 1:38 pm

Hi,

First of all, thank you plusminus for your great tutorials.

And thank you very much sapiezynski for answering so quickly! What I did at the beginning was right but I hadn't the good URL to send the request to and I didn't know about the JSONTokener.

I'm gonna try it right know!

Squallco
User avatar
Squallco
Freshman
Freshman
 
Posts: 3
Joined: Tue May 04, 2010 12:50 pm
Location: France

Postby xavi911 » Wed May 12, 2010 11:08 am

plusminus wrote:
quauhtlimtz wrote:It is not clear for me why use this way to locate people if you have the GPS option that is even more accurate. What are the advantages about using this way to locate people???


Hello quauhtlimtz,

there is exactly NO advantage, except the fact that perhaps not all phones come with a GPS-chip ;).

Regards,
olusminus



Hey dude I need to insert a map inside a tab. Can you help me xle2911@hotmail.com add me !!!?
User avatar
xavi911
Freshman
Freshman
 
Posts: 2
Joined: Wed May 12, 2010 10:59 am
Location: spain

Top

Re: Poor mans GPS - Cell(Tower)ID / Location Area Code -Look

Postby Shaba1 » Fri May 21, 2010 3:44 am

How about posting the AndroidManifest.xml file for this also.
Shaba1
Freshman
Freshman
 
Posts: 5
Joined: Fri Apr 09, 2010 8:55 pm

Re: Poor mans GPS - Cell(Tower)ID / Location Area Code -Look

Postby Sivan » Thu Jul 15, 2010 1:34 pm

Hi plusminius....

Wats the project details :::

Package name: ?
Application name: ?
Project name: ?
Activity name: ?
SDK version : ?

These details would be perfect for my application ....

Thanks
Sivan
Junior Developer
Junior Developer
 
Posts: 14
Joined: Mon Jul 05, 2010 10:02 am
Location: Bangalore , India

Re: Poor mans GPS - Cell(Tower)ID / Location Area Code -Look

Postby LiuXun » Thu Feb 10, 2011 5:26 am

Hi,I also wanna know , Does the "Secret" API proposed by plusminus still works now?? Had google stopped it?
LiuXun
Once Poster
Once Poster
 
Posts: 1
Joined: Thu Feb 10, 2011 5:11 am

Re: Poor mans GPS - Cell(Tower)ID / Location Area Code -Look

Postby saurabhpatel » Fri May 27, 2011 8:37 am

it can be working in india???
www.google.com/glm/mmap working in india???
saurabhpatel
Once Poster
Once Poster
 
Posts: 1
Joined: Fri May 27, 2011 8:35 am

Re: Poor mans GPS - Cell(Tower)ID / Location Area Code -Look

Postby sri2thayu » Tue May 31, 2011 5:03 pm

Poor mans GPS - Cell(Tower)ID / Location Area Code...i want this app wat i do?
sri2thayu
Once Poster
Once Poster
 
Posts: 1
Joined: Tue May 31, 2011 4:53 pm

Re: Poor mans GPS - Cell(Tower)ID / Location Area Code -Look

Postby baponk » Sat Dec 03, 2011 8:17 pm

hi plusminus.

how do i know cellid by cell phone number..


very2 usefull article..
thx
baponk
Once Poster
Once Poster
 
Posts: 1
Joined: Sat Dec 03, 2011 8:12 pm

Re: Poor mans GPS - Cell(Tower)ID / Location Area Code -Look

Postby Fatemy » Mon Dec 19, 2011 2:16 am

hi !
please what version of android you've used to create this project
cuz i've tryed for hours now without success i'm stuck at several class's problems
and how i can make this source code compatible to android 2.2 , i will be thankfull if somoene have this project compilable and can send me it to Fatemy.reda@gmail.com
Fatemy
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Dec 19, 2011 2:05 am

Re: Poor mans GPS - Cell(Tower)ID / Location Area Code -Look

Postby karinca » Thu Mar 15, 2012 10:23 am

hi everyone,

I tried to write this code but i did not get success. When i create JSONObject, i was faced with some problem. For example ; query order does not fit given example. And also I cannot get neighboring cell info (samsung galaxy pro android 2.2) so i do not write complite query. if someone helps me, i will so glad.

Regards
karinca
Once Poster
Once Poster
 
Posts: 1
Joined: Thu Mar 15, 2012 10:15 am

Top
Previous

Return to Map Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest