【问题标题】:Android Location Manager?安卓位置管理器?
【发布时间】:2011-06-03 00:49:12
【问题描述】:

我要做的就是从最后一个已知位置返回 long/lat 值,如果为 null,则拉取新坐标。

我对此很陌生,这就是我所拥有的:

import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.TextView;

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


        LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 
        Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        double longitude = location.getLongitude();
        double latitude = location.getLatitude();


        TextView output;

        output = (TextView) findViewById(R.id.output);


        output.append("\n\nLocations (starting with last known):");
        Location location = locationManager.getLastKnownLocation(bestProvider);
        printLocation(location);



    }
}

【问题讨论】:

  • 你得到了什么错误或者你的EditText的输出是什么?
  • 它只是强制关闭,我什至无法运行它。
  • 在这种情况下,您应该发布 LogCat 输出。

标签: android locationmanager


【解决方案1】:

并且不要忘记将ACCESS_COARSE_LOCATIONACCESS_FINE_LOCATION 权限添加到您的AndoidManifest.xml。

【讨论】:

  • 我有 Fine_location 但我添加了 rough_location - 仍然强制关闭。感谢您的建议,我确信这是众多错误之一。
  • 如果您请求ACCESS_FINE_LOCATION(并已授予)您不需要ACCESS_COARSE_LOCATION,则会自动授予。
【解决方案2】:

检查位置,如果它们为空,则必须使用 locationManager.requestLocationUpdates(...) 函数。

我认为您还必须实现一个位置侦听器,以便在实时条件下有效地工作。

我已经回复here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-05
    • 1970-01-01
    • 1970-01-01
    • 2011-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多