How do you get your current position in Android?


       I was wondering if there was a straight forward way to get the current location from an android device.  I tried looking on the Android Developer site, but their examples only confused me... and also seemed like a very roundabout way to do something so simple, which made me think I missed something in the translation..?

Could anyone point me to a more simpler straight forward tutorial?

Thanks in advance!
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Are you looking for an app that will do this or how to code this in android?

There is an app called maverick that will give yours coordinates
errangAuthor Commented:
I'm trying to code this
Try this link:

It has a tutorial on gps for android with done code samples.
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

Try this link:

It has a tutorial on gps for android with done code samples.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
errangAuthor Commented:
Hm... tried the code at the link, and it runs without errors...

But I'm having trouble getting it to run on the emulator, the command telnet localhost 5554 isn't working... is there another way around this?
Dejan PažinHead of SW DevelopmentCommented:
>> the command telnet localhost 5554 isn't working

What happens when you try this? It should work if the emulator is started.
errangAuthor Commented:
It just says connection refused.  Tried this on ubintu and Mac OSX.

I ran this command in the terminal after starting the simulator.
Dejan PažinHead of SW DevelopmentCommented:

The port number of the emulator should be displayed in the title of the emulator window. Like this: 5554 MyEmulator

What does it say in your emulator?
errangAuthor Commented:
>>The port number of the emulator should be displayed in the title of the emulator window. Like this: 5554 MyEmulator

Hm, never noticed that before... but mine says 5554.

The connection works now for some odd reason after restarting... but I still see a blank screen on the emulator.

This is what I have... do I have it right?


import android.content.Context;

import android.location.Location;

import android.location.LocationListener;

import android.location.LocationManager;

import android.os.Bundle;

import android.widget.TextView;
import android.widget.Toast;

import java.*;

public class MapsTest extends Activity


/** Called when the activity is first created. */


public void onCreate(Bundle savedInstanceState)




/* Use the LocationManager class to obtain GPS locations */

LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);

LocationListener mlocListener = new MyLocationListener();

mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);


/* Class My Location Listener */

public class MyLocationListener implements LocationListener



public void onLocationChanged(Location loc)




//String Text = “My current location is: “ + “Latitud = “ + loc.getLatitude() + “Longitud = “ + loc.getLongitude();

String Text = "My current location is:" + "latitude = " + loc.getLatitude() + "Longitude = " + loc.getLongitude();
TextView tv = (TextView) findViewById(;
Toast.makeText( getApplicationContext(), Text, Toast.LENGTH_SHORT).show();



public void onProviderDisabled(String provider)


Toast.makeText( getApplicationContext(), "Gps Disabled", Toast.LENGTH_SHORT ).show();



public void onProviderEnabled(String provider)


Toast.makeText( getApplicationContext(), "Gps Enabled", Toast.LENGTH_SHORT).show();



public void onStatusChanged(String provider, int status, Bundle extras)



}/* End of Class MyLocationListener */

}/* End of UseGps Activity */

Open in new window

<?xml version="1.0" encoding="utf-8"?>
    <TextView android:text="TextView" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>

Open in new window

Dejan PažinHead of SW DevelopmentCommented:

Do you have Maps API Key from Google? You have to get one in order to use the maps. Here is how you get it:
errangAuthor Commented:
Yes, I got the google maps API key using keytool.
Dejan PažinHead of SW DevelopmentCommented:

The application works fine - it tells you the current location when you change it.

There is no map view in this example, it is only an appication which tells you the current location.

So, you start the app and then change the location through the telnet and the coordinates will be displayed on the blank screen. Thats it, no map view involved.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.