6

I'm currently testing gps locations in Android(with SDK Tools rev 21.0.1. I tried the standard procedure:

  1. Create an emulator with GPS enabled(tried multiple version, from 2.1 to 4.2)
  2. Start the emulator
  3. telnet to localhost:5554
  4. Type geo fix long lat

In theory, this should set the gps to .

But the following signs indicate the location is not properly set:

1. When I go to maps.google.com or open Google map, it always complains that cannot decide my location and they always ask me to switch on wifi.

2. The GPS never seems to be activated -- no icons on the status bar.

Also, I tried DDMS(which is deprecated and of course I tried Monitor as well). Nothing seems to happen.

I went previous links pointed here: Location not being updated on new geo fix in android emulator

Android - Unable to get the gps location on the emulator

GPS on emulator doesn't get the geo fix - Android

But all those links do not seem to help. There are some bug report on android project page: http://code.google.com/p/android/issues/detail?id=13046

but it was a pretty old issue and a final solution wasn't reached.

I'm wondering if anyone else has experienced similar issue and please offer some help. Thanks.

Community
  • 1
  • 1
kkspeed
  • 373
  • 2
  • 9
  • I absolutely can confirm that. It doesn't work. Interestingly if I setup an AVD with Android 2.1 (or something other very old) it works like a charm: geo fix long lat and the location is shown immediately in Google Maps app... – decades Feb 21 '13 at 20:55

2 Answers2

1

hope You will see icon and it will work.working on mine. APi Level 10

package com.example.locationsddf;

import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;

public class MainActivity extends Activity {

    LocationManager lm;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final TextView tv = (TextView) findViewById(R.id.tv);
        lm = (LocationManager) getSystemService(LOCATION_SERVICE);
        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new LocationListener() {

            @Override
            public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onProviderEnabled(String arg0) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onProviderDisabled(String arg0) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onLocationChanged(Location arg0) {
                tv.setText("Latitude: "+arg0.getLatitude()+" \nLongitude: "+arg0.getLongitude());

            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

}

Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.locationsddf"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="5"
        android:targetSdkVersion="10" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.locationsddf.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

When icon is notified then you can just simply get the location by lm.getLastKnowLocationit will work

Usman Riaz
  • 2,920
  • 10
  • 43
  • 66
  • I just followed your code and I can confirm that the onLocationChanged event was fired and the locations were received. But, why for apps like Google map, don't they respond to the GPS location change and still show messages like "unable to decide your location"? – kkspeed Feb 10 '13 at 09:23
  • If Thats the ans you can mark my post as Ans by ticking left top corner of my post. can you post your `Logcat` informataion? – Usman Riaz Feb 10 '13 at 14:13
0

Sometimes there are issues with AVD itself. Try switching to another CPU architecture. I had similar issues and that was resolved by switching between ARM and Intel. Sometimes AVD with Google services enabled also helped

Also play around with "Allow Mock Locations" in Developers options

As an alternative, you could try this client: https://github.com/RomanTheLegend/Pokemon_NoGo/tree/master/Sources/PokemonNoGo I wrote it to play Pokemons, but it works with any GPS-based app. All it does is accept coordinates from desktop client and mocks main system GPS provider - LocationManager.GPS_PROVIDER

Last but not least: in AVD you can replay .kml files. There are many services which could help you generate one. Or just install "Lockito" and generate fake coordinates from Android

the.Legend
  • 626
  • 5
  • 13