问题描述
public class GrayMapsActivity extends AppCompatActivity implements OnMapReadyCallback {
private GoogleMap mMap;
LocationManager locationManager;
public Location currentlocation;
public String s1,s2;
public Double d1,d2;
TextView txt1,txt2;
private FusedLocationProviderClient fusedLocationClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
d1=0.0;
d2=0.0;
super.onCreate(savedInstanceState);
fusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
setContentView(R.layout.activity_gray_maps_activity);
SupportMapFragment mapFragment = (SupportMapFragment)
getSupportFragmentManager().findFragmentById(R.id.map);
assert mapFragment != null;
mapFragment.getMapAsync(this);
txt1 = (TextView) (findViewById(R.id.textView1));
txt2 = (TextView) (findViewById(R.id.textView2));
if (ActivityCompat.checkSelfPermission(this,Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
fusedLocationClient.getLastLocation()
.addOnSuccessListener(this,new OnSuccessListener<Location>() {
@Override
public void onSuccess(Location location) {
// Got last kNown location. In some rare situations this can be null.
if (location != null) {
d1= location.getLatitude();
d2= location.getLongitude();
}
}
});
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
LatLng graycarlocation= new LatLng(d1,d2);
mMap.addMarker(new MarkerOptions()
.position(graycarlocation)
.title("Gray Car Location"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(graycarlocation));
}
}
“这是主要活动,我使用融合位置来获取最后一个已知位置,然后将其插入到双变量中的经度和纬度,由于某种原因,当地图开始时它不会到达该位置,
出现的错误代码: 尝试在空对象引用上调用虚拟方法“double java.lang.Double.doubleValue()” "
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)