I'm currently testing gps locations in Android(with SDK Tools rev 21.0.1. I tried the standard procedure:
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.
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".
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.
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.getLastKnowLocation
it will work
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With