从GPS获取高度/纬度/经度

时间:2011-06-29 17:45:19

标签: android android-location

我正在尝试运行下面的代码来获取用户位置(海拔/纬度/经度),但它不起作用。在调试过程中出现以下消息:

_ 运行时没有命令输出:'am start -D -n net.learn2develop.get_location / net.learn2develop.get_location.Getting_CoordinatesActivity -a android.intent.action.MAIN -c android.intent.category。启动器'在设备模拟器-5554 _

com.android.ddmlib.ShellCommandUnresponsiveException 在com.android.ddmlib.AdbHelper.executeRemoteCommand(AdbHelper.java:408) com.android.ddmlib.Device.executeShellCommand(Device.java:276) at 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) com.android.ddmlib.MonitorThread.run

可能有什么不对/丢失?

清单:

<?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); 


    }



}

提前致谢

1 个答案:

答案 0 :(得分:0)

尝试通过DDMS透视图发送lat和long坐标。