devxlogo

Location-Based Services Using CellID in Android

Location-Based Services Using CellID in Android

n earlier article about Android showed you how to interface with GPS receivers to obtain the geographical position of a device. However, not all today’s mobile devices have built-in GPS receivers. Moreover, GPS does not work indoors. This seriously limits the usefulness of applications built around GPS technologies. One good way to expand the utility of your LBS services is to use your device’s cell ID. This article will show you how to obtain the cell ID of an Android device and then use the Google Maps API to translate this cell ID value into latitude and longitude.

Author’s Note: Click here for a discussion on using Cell ID for location-based services using a Windows Mobile device.

Creating the Project

Using Eclipse, create a new Android project and name it CellID. In main.xml, add a and view:

      
Figure 1. How Your App Should Look: The UI of your LBS application.

This will create the layout you see Figure 1.

Because this application requires Internet connectivity along with access to cell location information, add the relevant permission to the AndroidManifest.xml file:

                                                                                        

In the CellID.java file, import the following packages:

import java.io.DataInputStream;import java.io.DataOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.net.HttpURLConnection;import java.net.URL;import java.net.URLConnection;import android.app.Activity;import android.content.Intent;import android.net.Uri;import android.os.Bundle;import android.telephony.gsm.GsmCellLocation;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.TextView;

 

devx-admin

Share the Post: