无法使用Google地球获取手机当前位置

时间:2016-10-24 14:43:51

标签: android google-maps gps

我对Android编程很新,并且正在寻找谷歌地球。我希望能够使用GPS找到我的手机当前位置。我按照了一些在线教程,得到了以下代码。

 public boolean sendDeviceEvent() {
    boolean status = false;
    try {
        device.sendEvent("blah...blah");
        status = true;
    } catch (Exception e) {
        log.error("Failed to send NodeLowBattery Event - {} {}", createNodeLowBatteryNotification(), e.getCause());
    } finally {
        return status;
    }
}

这些是我的明显权限:

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

    private GoogleMap mMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);

        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);

    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;

        // Add a marker in Sydney and move the camera
        LatLng Uni = new LatLng(53.767735, -0.368377);
        mMap.addMarker(new MarkerOptions().position(Uni).title("University"));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(Uni));

        if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
            mMap.setMyLocationEnabled(true);
        }

    }

}    

我见过人们使用它并且它工作正常但是当我在手机上打开它时我会正确加载地图但没有当前位置。

非常感谢任何帮助。谢谢。

0 个答案:

没有答案