【发布时间】:2018-08-01 06:09:52
【问题描述】:
我想在我的应用程序中获取经度和纬度的值,我已经做到了,但问题是我得到带有值的负号。虽然值是正确的,但不知道为什么要得到带有值的负号。
java类代码:
package com.vshine.neuron.testing;
import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class code extends AppCompatActivity implements LocationListener {
private TextView textView;
private LocationManager locationManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_code);
textView = findViewById(R.id.tv);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
// TODO: Consider calling
// ActivityCompat#requestPermissions
// here to request the missing permissions, and then overriding
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
// int[] grantResults)
// to handle the case where the user grants the permission. See the documentation
// for ActivityCompat#requestPermissions for more details.
return;
}
Location location = locationManager.getLastKnownLocation(locationManager.NETWORK_PROVIDER);
onLocationChanged(location);
}
@Override
public void onLocationChanged(Location location) {
double longitude = location.getLongitude();
double latitude = location.getLatitude();
textView.setText("Longitude: " + longitude + "\n\n" + "Latitude: " + latitude);
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
}
【问题讨论】:
-
纬度和经度坐标可以采用负值,例如,参见this MSDN article,其中讨论了这一点。不,您的代码没有损坏。
-
@TimBiegeleisen 问题是当我输入这些 LatLong 时我没有得到 mylocation 意味着我没有得到正确的 LatLong?