I have been trying for some time to get the current location on my emulator. I have tried several samples that I found online but to no success. I...

How It Works

Get an answer in three easy steps. Here's how it works...

Ask Your Question

1. Ask Your Question

Enter your smartphone question at the top of this page and click Get An Answer.

Pick Your Priority

2. Pick Your Priority

Tell us how quickly you want your smartphone question answered.

Get An Answer

3. Get An Answer

Connect with your Smartphone tech via online chat or telephone call.

Answer

Customer

I have been trying for some time to get the current location on my emulator. I have tried several samples that I found online but to no success. I also tried using the google maps application thinking maybe it something to do with the code but still didn't work. The avd has gps hardware set, I tried wiping user data, sending geo fix commands, switching the latitude and longitude since some claim they needed to be reversed and enabling gps and wifi location on the emulator . I am using a 64 bit windows 7 application with eclipse but I also tried using Unbunu thinking its an OS related issue but to no success. If anyone can help me out it would be greatly appreciated since I tried almost anything that came to mind or read.

Posted
Alexey Schekin
Smartphone Tech

Hello!
Could you please provide part of code responsible to listen location? Does it show any errors, messages in logCat? Here is an examples how to make simple app with google maps in android:
http://www.codeproject.com/KB/android/GPSLocator.aspx
http://developer.android.com/guide/tutorials/views/hello-mapview.html
http://developer.android.com/resources/tutorials/views/hello-mapview.html

The most important things you should do are:
1. Gain API key to get ability to display map. If you didn't the map just will not show, but app still will be possible to show your location and get coordinates
2. Set permission to manifest:

  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />  
  <uses-permission android:name="android.permission.INTERNET" />

for wifi and gps.
3. Add google map library:

<application android:icon="@drawable/icon" android:label="@string/app_name">
<uses-library android:name="com.google.android.maps" />

4.To enable locationlistner you simple need to paste this code in your app:

  mapView = (MapView) findViewById(R.id.mapView);

  // enable Street view by default
  mapView.setStreetView(true);

  // enable to show Satellite view
  // mapView.setSatellite(true);

  // enable to show Traffic on map
  // mapView.setTraffic(true);

  mapView.setBuiltInZoomControls(true);

  mapController = mapView.getController();
  mapController.setZoom(16); 


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

  locationListener = new GPSLocationListener();

  locationManager.requestLocationUpdates(
    LocationManager.GPS_PROVIDER, 
    0, 
    0, 
    locationListener);

....

private class GPSLocationListener implements LocationListener 
{
  @Override
  public void onLocationChanged(Location location) {
    if (location != null) {
      GeoPoint point = new GeoPoint(
          (int) (location.getLatitude() * 1E6), 
          (int) (location.getLongitude() * 1E6));

      Toast.makeText(getBaseContext(), 
          "Latitude: " + location.getLatitude() + 
          " Longitude: " + location.getLongitude(), 
          Toast.LENGTH_SHORT).show();

      mapController.animateTo(point);
      mapController.setZoom(16);
      mapView.invalidate();
    }
  }

  ...
}
  1. To get location on emulator you need stable direct(or via proxy if it present) internet connection or you ddms service - android-sdk-windows\tools\ddms.bat -> emulator control -> send gps.
    I do this few times it should works. If you still will get problems, send me a piece of responcible code.

also look:
http://codemagician.wordpress.com/2010/05/06/android-google-mapview-tutorial-done-right/
http://www.devx.com/wireless/Article/39145/1954
http://stackoverflow.com/questions/2973290/check-wifi-and-gps-isconnected-or-not-in-android

Posted

quoteTestimonialsquote

About ExpertHelp

ExpertHelp is changing the way you connect with service professionals.

Whether you have a quick question while preparing your taxes, troubleshooting a computer problem, or need to hire an attorney, ExpertHelp is the most convenient and affordable way to connect with the right service professional to get the job done.

ExpertHelp has been in business since 2011, is an A+ Rated Better Business Bureau accredited member, and offers a 100% satisfaction guarantee on every question you ask!

More Smartphone Questions...

Ask Your Smartphone Question & Get An Answer Now!