我想从随机位置显示街景和地图。 但是我有问题它不起作用。 地图没有任何坐标,街景显示黑屏。 我提到了https://developers.google.com/maps/documentation/android-sdk/streetview?hl=ko。 请给我一个答案。
public class MapActivity extends AppCompatActivity implements GoogleMap.OnMarkerDragListener,OnStreetViewPanoramaReadyCallback, StreetViewPanorama.OnStreetViewPanoramaChangeListener {
private static final String MARKER_POSITION_KEY ="MarkerPosition";
double lat = (Math.random() *(85*2) ) - 85;
double lng = (Math.random() *(180*2)) - 180;
private LatLng random = new LatLng(-33.57365,151.20689);
private StreetViewPanorama mStreetViewPanorama;
private Marker mMarker;
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
final LatLng markerPosition;
if(savedInstanceState ==null){
markerPosition= random;
}else {
markerPosition = savedInstanceState.getParcelable(MARKER_POSITION_KEY);
}
SupportStreetViewPanoramaFragment streetViewPanoramaFragment =
(SupportStreetViewPanoramaFragment)getSupportFragmentManager().
findFragmentById(R.id.streetviewpanorama);
streetViewPanoramaFragment.getStreetViewPanoramaAsync(new OnStreetViewPanoramaReadyCallback() {
@Override
public void onStreetViewPanoramaReady(StreetViewPanorama streetViewPanorama) {
mStreetViewPanorama = streetViewPanorama;
mStreetViewPanorama.setOnStreetViewPanoramaChangeListener(
MapActivity.this);
if(savedInstanceState == null){
mStreetViewPanorama.setPosition(random);
}
}
});
SupportMapFragment mapFragment=
(SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap googleMap) {
googleMap.setOnMarkerDragListener(MapActivity.this);
mMarker = googleMap.addMarker(new MarkerOptions()
.position(random)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.pegman))
.draggable(true));
}
});
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putParcelable(MARKER_POSITION_KEY,mMarker.getPosition());
}
@Override
public void onMarkerDragEnd(Marker marker) {
mStreetViewPanorama.setPosition(marker.getPosition(),150);
}
@Override
public void onStreetViewPanoramaChange(StreetViewPanoramaLocation streetViewPanoramaLocation) {
if (streetViewPanoramaLocation != null) {
mMarker.setPosition(streetViewPanoramaLocation.position);
}
}
}