从 GPS 获取高度/纬度/经度
我正在尝试运行下面的代码来获取用户位置(海拔/纬度/经度),但它不起作用。在调试过程中出现以下消息:
_运行时无命令输出:'am start -D -n net.learn2develop.get_location/net.learn2develop.get_location.Getting_CooperativesActivity -a android.intent.action.MAIN -c设备模拟器上的 android.intent.category.LAUNCHER-5554_
com.android.ddmlib.ShellCommandUnresponsiveException 位于 com.android.ddmlib.AdbHelper.executeRemoteCommand(AdbHelper.java:408) 位于 com.android.ddmlib.Device.executeShellCommand(Device.java:276) 位于 com.android.ide.eclipse.adt.internal.launch.ActivityLaunchAction.doLaunchAction(ActivityLaunchAction.java:74) 位于 com.android.ide.eclipse.adt.internal.launch.AndroidLaunchController.launchApp(AndroidLaunchController.java:1147) 位于 com.android.ide.eclipse.adt.internal.launch.AndroidLaunchController.clientChanged(AndroidLaunchController.java:1493) 位于 com.android.ddmlib.AndroidDebugBridge.clientChanged(AndroidDebugBridge.java:870) 位于 com.android.ddmlib.Device.update(Device.java:398) 位于 com.android.ddmlib.Client.update(Client.java:835) 位于 com.android.ddmlib.HandleAppName.handleAPNM(HandleAppName.java:90) 位于 com.android.ddmlib.HandleAppName.handleChunk(HandleAppName.java:64) 位于 com.android.ddmlib.MonitorThread.callHandler(MonitorThread.java:414) 位于 com.android.ddmlib.MonitorThread.processClientActivity(MonitorThread.java:322) at com.android.ddmlib.MonitorThread.run(MonitorThread.java:263)
可能有什么问题/缺失?
清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.learn2develop.get_location"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Getting_CoordinatesActivity"
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>
Java 代码:
package net.learn2develop.get_location;
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.Toast;
public class Getting_CoordinatesActivity extends Activity {
private LocationManager myLocationManager;
private LocationListener myLocationListener;
public void onLocationChanged(Location location) {
String Text = "Latitude = " + location.getLatitude() +
"\nLongitude = " + location.getLongitude() +
"\nAltitude = " + location.getAltitude();
Toast.makeText( getApplicationContext(), Text, Toast.LENGTH_LONG ).show();
}
public void onProviderDisabled(String provider) {
}
public void onProviderEnabled(String provider) {
}
public void onStatusChanged(String provider, int status, Bundle extras) {
}
protected void onDestroy(){
super.onDestroy();
//getLocationManager().removeUpdates( this );
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
myLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
0, 0, myLocationListener);
}
}
提前致谢
I am trying to run the code below to get the user location (altitude/latitude/longitude) but it's not working. During the debugging is appearing the following message:
_No command output when running: 'am start -D -n net.learn2develop.get_location/net.learn2develop.get_location.Getting_CoordinatesActivity -a android.intent.action.MAIN -c android.intent.category.LAUNCHER' on device emulator-5554_
com.android.ddmlib.ShellCommandUnresponsiveException
at com.android.ddmlib.AdbHelper.executeRemoteCommand(AdbHelper.java:408)
at com.android.ddmlib.Device.executeShellCommand(Device.java:276)
at com.android.ide.eclipse.adt.internal.launch.ActivityLaunchAction.doLaunchAction(ActivityLaunchAction.java:74)
at com.android.ide.eclipse.adt.internal.launch.AndroidLaunchController.launchApp(AndroidLaunchController.java:1147)
at com.android.ide.eclipse.adt.internal.launch.AndroidLaunchController.clientChanged(AndroidLaunchController.java:1493)
at com.android.ddmlib.AndroidDebugBridge.clientChanged(AndroidDebugBridge.java:870)
at com.android.ddmlib.Device.update(Device.java:398)
at com.android.ddmlib.Client.update(Client.java:835)
at com.android.ddmlib.HandleAppName.handleAPNM(HandleAppName.java:90)
at com.android.ddmlib.HandleAppName.handleChunk(HandleAppName.java:64)
at com.android.ddmlib.MonitorThread.callHandler(MonitorThread.java:414)
at com.android.ddmlib.MonitorThread.processClientActivity(MonitorThread.java:322)
at com.android.ddmlib.MonitorThread.run(MonitorThread.java:263)
What could be wrong/missing?
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.learn2develop.get_location"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="8"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Getting_CoordinatesActivity"
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>
Java Code:
package net.learn2develop.get_location;
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.Toast;
public class Getting_CoordinatesActivity extends Activity {
private LocationManager myLocationManager;
private LocationListener myLocationListener;
public void onLocationChanged(Location location) {
String Text = "Latitude = " + location.getLatitude() +
"\nLongitude = " + location.getLongitude() +
"\nAltitude = " + location.getAltitude();
Toast.makeText( getApplicationContext(), Text, Toast.LENGTH_LONG ).show();
}
public void onProviderDisabled(String provider) {
}
public void onProviderEnabled(String provider) {
}
public void onStatusChanged(String provider, int status, Bundle extras) {
}
protected void onDestroy(){
super.onDestroy();
//getLocationManager().removeUpdates( this );
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
myLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
0, 0, myLocationListener);
}
}
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试通过 DDMS 视角发送纬度和经度坐标。
Try sending lat and long coordinates through DDMS perspective.