Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android emulator geo fix is unable to set gps location

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.

like image 326
kkspeed Avatar asked Feb 09 '13 02:02

kkspeed


People also ask

How do I enable GPS on my emulator?

When setting up GPS emulator, you need to go to your Settings > About on your Android device. Then tap on the Build number seven times, which activates the developer mode. Now head back to the main settings, where you should see a new option menu called "Developer Options".

Where is the emulator folder in Android Studio?

On Windows, it's the %LocalAppData%\Android\Sdk directory. This normally expands to C:\Users\<username>\AppData\Local\Android\Sdk , although it might vary based on your system. On macOS, it's the $HOME/Library/Android/sdk directory.


1 Answers

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

like image 131
Usman Riaz Avatar answered Oct 06 '22 07:10

Usman Riaz