简体   繁体   English

Android:显示多个街景(Google Maps Api)

[英]Android: Show multiple street views (Google Maps Api)

I have an xml file called activity_collage.xml with 2 street view fragments - I would like both fragments to display the street view of a given location - So a total of 2 street views on the screen 我有一个名为activity_collage.xml的xml文件,其中包含2个街景视图片段-我希望两个片段都显示给定位置的街景视图-所以屏幕上总共有2个街景视图

Here's my code: 这是我的代码:

public class Collage extends ActionBarActivity implements OnStreetViewPanoramaReadyCallback {

StreetViewPanoramaFragment topLeft, topRight;

static final LatLng posOne = new LatLng(43.771925, -79.512460);

static final LatLng posTwo = new LatLng(43.790634, -79.193632); 

Here's where I initialize my 2 StreetViewFragment objects in my onCreate() method 这是在我的onCreate()方法中初始化2个StreetViewFragment对象的地方

topLeft =
            (StreetViewPanoramaFragment) getFragmentManager()
                    .findFragmentById(R.id.picTL);
    topLeft.getStreetViewPanoramaAsync(this);

    topRight =
            (StreetViewPanoramaFragment) getFragmentManager()
                    .findFragmentById(R.id.picTR);

Here's the overridden method from the OnStreetViewPanoramaReadyCallback interface ... 这是OnStreetViewPanoramaReadyCallback接口的重写方法...

@Override
public void onStreetViewPanoramaReady(StreetViewPanorama panorama) {
    panorama.setPosition(posOne);


}

But how do I set the street view for topRight? 但是,如何设置topRight的街景?

According to http://code.google.com/p/gmaps-api-issues/issues/detail?id=6953 , multiple StreetViewPanorama Objects are not supported. 根据http://code.google.com/p/gmaps-api-issues/issues/detail?id=6953 ,不支持多个StreetViewPanorama对象。 In my experience, no explicit errors occur, but the second StreetViewPanorama will remain blank. 以我的经验,没有任何明显的错误发生,但是第二个StreetViewPanorama将保持空白。

Frustratingly, I don't think the documentation was updated like the above thread indicates it should have been. 令人沮丧的是,我不认为文档的更新如上述主题所示。

I have the same problem with my fragment XML containing 2 fragments : map fragment, and StreetViewPanoramaFragment. 我的片段XML包含2个片段,我也遇到了同样的问题:地图片段和StreetViewPanoramaFragment。 StreetView stays blank. 街景视图保持空白。 I managed to use it with a simple view instead of fragment. 我设法用一个简单的视图而不是片段。

With Kotlin it gives : 使用Kotlin,它可以:

val myFrag=getView()!!.findViewById<StreetViewPanoramaView>(R.id.street_view_panorama)
    myFrag.onCreate(savedInstanceState);
    myFrag.getStreetViewPanoramaAsync(OnStreetViewPanoramaReadyCallback { panorama ->
        panorama.setPosition(LatLng(55.758818, 37.620587))
        svPano = panorama
    })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM