Все в порядке, результат ожидаемый.
Вот выходное изображение

Но отображение карт занимает много времени: здесь загружаются изображения, а затем отображаются карты. Есть ли способ сначала показать карты, а затем загрузить изображения и установить маркеры.
Вот код, который я пробовал
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
MapsInitializer.initialize(this);
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
assert locationManager != null;
String provider = locationManager.getBestProvider(criteria, true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
requestPermissions(new String[]{
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION
}, LOCATION_REQUEST_CODE);
return;
}
}
mLastLocation = locationManager.getLastKnownLocation(provider);
userLatLng = new LatLng(mLastLocation.getLatitude(), mLastLocation.getLongitude());
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(userLatLng, 14.0f));
mMap.setMyLocationEnabled(true);
mMap.getUiSettings().setZoomControlsEnabled(true);
mMap.setBuildingsEnabled(true);
try {
businessBitmap = new AddMarkers(imgUrl2).execute().get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
if (businessLatLng != null) {
businessMarker = mMap.addMarker(new MarkerOptions()
.position(businessLatLng)
.title(businessUser)
.snippet(getLocation(businessLatLng))
.icon(BitmapDescriptorFactory.fromBitmap(getMarkerBitmapFromView(businessBitmap))));
} else {
businessMarker = mMap.addMarker(new MarkerOptions()
.position(businessLatLng)
.title(businessUser)
.snippet(getLocation(businessLatLng)));
}
try {
userBitmap = new AddMarkers(imgUrl).execute().get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
if (mLastLocation != null) {
if (userBitmap != null) {
userMarker = mMap.addMarker(new MarkerOptions().position(userLatLng)
.title(username)
.snippet(getLocation(userLatLng))
.icon(BitmapDescriptorFactory.fromBitmap(getMarkerBitmapFromView(userBitmap))));
} else {
userMarker = mMap.addMarker(new MarkerOptions().position(userLatLng)
.title(username)
.snippet(getLocation(userLatLng)));
}
}
if(!(userLatLng == null || businessLatLng == null)) {
Polyline distanceLine = mMap.addPolyline(new PolylineOptions().add(userLatLng, businessLatLng).width(4).color(Color.GREEN));
}
}
Я использую asynctask для загрузки изображений, вот код для этого
public AddMarkers(String imgUrl) {
this.imgUrl = imgUrl;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
pd = new ProgressDialog(MapsActivity.this);
pd.setTitle("Loading");
pd.setMessage("Please wait..");
pd.show();
}
@Override
protected Bitmap doInBackground(Void... voids) {
URL url;
try {
url = new URL(imgUrl);
return BitmapFactory.decodeStream(url.openConnection().getInputStream());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Bitmap bitmap) {
super.onPostExecute(bitmap);
if (pd != null && pd.isShowing()) pd.dismiss();
}
}
Подробнее здесь: https://stackoverflow.com/questions/476 ... ge-markers
Мобильная версия