Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/180.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android GPS:loc.getLatitude/Longitude的结果始终为0.0_Android_Get_Gps - Fatal编程技术网

Android GPS:loc.getLatitude/Longitude的结果始终为0.0

Android GPS:loc.getLatitude/Longitude的结果始终为0.0,android,get,gps,Android,Get,Gps,我使用教程来编写我的应用程序。我使用DDMS位置管理器虚拟更改我的位置 不幸的是,对于long和lat,我总是得到一个0.0的位置。即使我稍后在prog中使用locationchanged方法切换它们,我也得到了0.0 代码如下: @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main)

我使用教程来编写我的应用程序。我使用DDMS位置管理器虚拟更改我的位置

不幸的是,对于long和lat,我总是得到一个0.0的位置。即使我稍后在prog中使用locationchanged方法切换它们,我也得到了0.0

代码如下:

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

  //---use the LocationManager class to obtain GPS locations---
    lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);    
    locationListener = new MyLocationListener();
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener); 

    Location lastLoc = lm.getLastKnownLocation("gps");

    curLocation = "Standort: \nLatitude: " + lastLoc.getLatitude() + "\nLongitude: " + lastLoc.getLongitude();

    upperText = (TextView) findViewById(R.id.TextView01);
    upperText.setText(curLocation);
}

有些东西不见了,但我不知道是什么…:/


如果有人能帮忙,我会非常高兴的

转到地图默认应用程序并允许用户允许纬度和经度选项。在我们的应用程序中,当GPS信号闪烁且停止时,我们将获得纬度和经度。这对我来说很有效

您是否通过纬度/经度:48.02003或48020203?我在DDMS中写入48.020203。这是一个要点。我使用了位置管理器的默认输入,但也不起作用。
    @Override
    public void onLocationChanged(Location loc) 
    {
        if (loc != null) {
            Toast.makeText(getBaseContext(), 
                "Location changed : Lat: " + loc.getLatitude() + 
                " Lng: " + loc.getLongitude(), 
                Toast.LENGTH_SHORT).show();
        }

        if (loc != null) 
        {
            upperText.setText(curLocation + "\n\nStandort: \nLatitude: " + loc.getLatitude() 
                    + "\nLongitude: " + loc.getLongitude());
        }
    }