1

以下のコードを使用して、ユーザーの現在の場所を取得します。このコードはエミュレーターで機能しますが、このアプリケーションをモバイルで使用すると、現在の緯度と経度を指定できません。<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />このコードをAndroidマニフェストファイルで 使用します。

解決策を教えてください...私のコードは以下のとおりです

public class MenuPage extends Activity{



@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.menupage);


     LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
     LocationListener locListener = new MyLocationListener();
     locationManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, locListener);



}

/*ユーザーの現在の場所を取得するためのクラスMyLocationListenerの開始*/

public class MyLocationListener implements LocationListener

{

    @Override

    public void onLocationChanged(Location crurrentLocation)

    {
          Log.v("WHERE ","onLocationChanged()");
          crurrentLocation.getLatitude(); // get current latitude
          crurrentLocation.getLongitude(); // get current longitude
           longitude=crurrentLocation.getLongitude();
           latitude=  crurrentLocation.getLatitude();

           Log.v("WHERE ","onLocationChanged()  Latitude="+latitude);   
           Log.v("WHERE ","onLocationChanged()  Longitude="+longitude); 
            Toast.makeText(getApplicationContext(),"Latitud="+crurrentLocation.getLatitude(),Toast.LENGTH_SHORT).show(); 
            Toast.makeText(getApplicationContext(),"Longitud="+crurrentLocation.getLongitude(),Toast.LENGTH_SHORT).show();

            send_current_location = new Send_Current_location_ToServer();
      // Send current location to server
            String server_message =  send_current_location.sendData(userid,latitude,longitude);    
         //   String text ="My current location is: " + "Latitud = " + crurrentLocation.getLatitude() + "Longitud = " + crurrentLocation.getLongitude();
         //   Toast.makeText(getApplicationContext(),text,Toast.LENGTH_SHORT).show();

    }

    @Override

    public void onProviderDisabled(String provider)

    {
          Log.v("WHERE ","onProviderDisabled()");
    Toast.makeText( getApplicationContext(),"Gps Disabled",Toast.LENGTH_SHORT ).show();

    }

    @Override

    public void onProviderEnabled(String provider)

    {
         Log.v("WHERE ","onProviderEnabled()");

    Toast.makeText( getApplicationContext(),"Gps Enabled",Toast.LENGTH_SHORT).show();

    }

    @Override

    public void onStatusChanged(String provider, int status, Bundle extras)

    {
         Log.v("WHERE ","onStatusChanged()");
    }

}/* End of Class MyLocationListener */

}

4

1 に答える 1

0

位置情報サービスに関する 2.3 エミュレーターにはバグがあります。コードをテストするには、2.1 に変更してみてください。

位置情報サービスの詳細については、これを使用してください。

バグの状況についてはこちらをご覧ください。

于 2011-06-20T13:59:29.167 に答える