【发布时间】:2016-07-31 10:18:00
【问题描述】:
为什么地图和位置在设备一加一(Marshmallow)上不起作用,但在其他设备上(我尝试在 Kitkat 和棒棒糖中工作)?这样就无法检测到我们的位置
这是我的代码
private void setMap() {
mMapFragment.getMapAsync(this);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PLACE_PICKER_REQUEST) {
if (resultCode == RESULT_OK) {
Place place = PlacePicker.getPlace(getApplicationContext(), data);
LatLng latLng = new LatLng(place.getLatLng().latitude, place.getLatLng().longitude);
googleMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
googleMap.animateCamera(CameraUpdateFactory.zoomTo(15));
}
}
}
@Override
public void onMapReady(GoogleMap googleMap) {
this.googleMap = googleMap;
this.googleMap.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
GoogleMapOptions option = new GoogleMapOptions();
option.compassEnabled(true);
this.googleMap.setTrafficEnabled(true);
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
googleMap.setMyLocationEnabled(true);
googleMap.setOnMyLocationChangeListener(myLocationChangeListener);
}
private OnMyLocationChangeListener myLocationChangeListener = new OnMyLocationChangeListener() {
@Override
public void onMyLocationChange(Location location) {
if(awal) {
awal=false;
googleMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(location.getLatitude(), location.getLongitude())));
googleMap.animateCamera(CameraUpdateFactory.zoomTo(13));
}
}
};
【问题讨论】:
标签: android google-maps