Android-如何获取当前位置(经度和纬度)?

| 我正在使用以下代码来获取当前位置(即纬度和经度),但是我没有得到当前位置(经度和纬度)。 有人知道为什么吗?
package com.ram.currentlocation;

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 Location_Gps extends Activity
{

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);

      /* Use the LocationManager class to obtain GPS locations */
      LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);

      LocationListener mlocListener = new MyLocationListener();
      mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener);
    }

    /* Class My Location Listener */
    public class MyLocationListener implements LocationListener
    {

      @Override
      public void onLocationChanged(Location loc)
      {

        loc.getLatitude();
        loc.getLongitude();

        String Text = \"My current location is: \" +
        \"Latitud = \" + loc.getLatitude() +
        \"Longitud = \" + loc.getLongitude();

        Toast.makeText( getApplicationContext(), Text, Toast.LENGTH_SHORT).show();
      }

      @Override
      public void onProviderDisabled(String provider)
      {
        Toast.makeText( getApplicationContext(), \"Gps Disabled\", Toast.LENGTH_SHORT ).show();
      }

      @Override
      public void onProviderEnabled(String provider)
      {
        Toast.makeText( getApplicationContext(), \"Gps Enabled\", Toast.LENGTH_SHORT).show();
      }

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

      }
    }
}
附注:我在
manifest
文件中使用了以下权限:
<uses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\"/>
<uses-permission android:name=\"android.permission.ACCESS_CORSE_LOCATION\"/>
    
已邀请:
您的清单文件中有错误。正确的一个是:
<uses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\"/>
    
您必须将位置信息发送给模拟器​​,因为模拟器是您需要提供位置信息的软件。 如果您使用的是eclipse,请转到
Window -> Show view -> Other
选择“ Android”选项卡,然后搜索模拟器控件。 在看到模拟器控制窗口后,导航至位置控件。 如您在下图所示 发送loc fix后,您可以使用
Location loc = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
如果“ 6”是“ 7”的对象,那么完成了90%的工作;) 干杯!     
在您的Android清单中,您是否设置了权限?
android.permission.ACCESS_FINE_LOCATION
至于仅获得(0,0)坐标,您可能正在使用模拟器。如果您使用的是eclipse,请转到模拟器控件,然后在底部将伪造的坐标发送到设备     
您使用的权限不正确。正确的是:
<uses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\" />
顺便说一句,您的需求只能通过以下方式满足:
<using-permission android:name=\"ACCESS_FINE_LOCATION\" />
因此不需要
ACCESS_COARSE_LOCATION
    

要回复问题请先登录注册