0

我正在开发一个需要显示街景的 android 应用程序,我决定使用谷歌街景 api。但是当我调用街景功能时,它会交换到“谷歌街景应用程序”而不是我的应用程序内......

是否可以在我的应用程序中显示街景?

4

3 回答 3

1

我认为还没有api。但是,您只需将其嵌入应用程序的 Web 浏览器 (WebView) 即可使用 Web 版本。是您目前最好的选择。

于 2013-10-16T08:32:11.193 回答
0

如前所述,

您无法使用 Google Maps Android API v2 将街景嵌入到您自己的应用程序中。

谷歌街景api:应用中的街景

于 2013-10-16T08:32:04.603 回答
0

是的!它可能我也在开发一个基于谷歌街景和距离 API 的应用程序。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.ronak.justforclone.MapsActivity" >


<LinearLayout
    android:id="@+id/map_container2"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="0.5"
    android:orientation="vertical">

    <fragment
        android:id="@+id/streetviewpanorama"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="0.5"
                   class="com.google.android.gms.maps.SupportStreetViewPanoramaFragment" />

    <fragment
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="0.5"
        class="com.google.android.gms.maps.SupportMapFragment"
        map:cameraTargetLat="-33.87365"
        map:cameraTargetLng="151.20689"
        map:cameraZoom="15" />
</LinearLayout>

通过这个你可以进行布局和java

 public class MapsActivity extends AppCompatActivity implements GoogleMap.OnMarkerDragListener, StreetViewPanorama.OnStreetViewPanoramaChangeListener {

private static final String MARKER_POSITION_KEY = "MarkerPosition";

// George St, Sydney
private static final LatLng SYDNEY = new LatLng(-33.87365, 151.20689);

private StreetViewPanorama mStreetViewPanorama;

private Marker mMarker;

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_maps);

    final LatLng markerPosition;
    if (savedInstanceState == null) {
        markerPosition = SYDNEY;
    } else {
        markerPosition =     savedInstanceState.getParcelable(MARKER_POSITION_KEY);
    }

    SupportStreetViewPanoramaFragment streetViewPanoramaFragment =
            (SupportStreetViewPanoramaFragment)
                    getSupportFragmentManager().findFragmentById(R.id.streetviewpanorama);
    streetViewPanoramaFragment.getStreetViewPanoramaAsync(
            new OnStreetViewPanoramaReadyCallback() {
                @Override
                public void onStreetViewPanoramaReady(StreetViewPanorama panorama) {
                    mStreetViewPanorama = panorama;
                       mStreetViewPanorama.setOnStreetViewPanoramaChangeListener(
                            MapsActivity.this);
                    // Only need to set the position once as the streetview fragment will maintain
                    // its state.
                    if (savedInstanceState == null) {
                        mStreetViewPanorama.setPosition(SYDNEY);
                    }
                }
            });

    SupportMapFragment mapFragment =
            (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
    mapFragment.getMapAsync(new OnMapReadyCallback() {
        @Override
        public void onMapReady(GoogleMap map) {
            map.setOnMarkerDragListener(MapsActivity.this);
            // Creates a draggable marker. Long press to drag.
            mMarker = map.addMarker(new MarkerOptions()
                    .position(markerPosition)
                    .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 onStreetViewPanoramaChange(StreetViewPanoramaLocation location) {
    if (location != null) {
        mMarker.setPosition(location.position);
    }
}

@Override
public void onMarkerDragStart(Marker marker) {
}

@Override
public void onMarkerDragEnd(Marker marker) {
    mStreetViewPanorama.setPosition(marker.getPosition(), 150);
}

@Override
public void onMarkerDrag(Marker marker) {
}
 }

有关更多信息,请查看此链接 https://developers.google.com/maps/documentation/android-api/streetview

通过这段代码你会得到类似的东西:D

于 2017-02-09T19:59:28.440 回答