Google Earth Api - programmatically enter StreetVi

2020-04-11 13:58发布

I'm trying to give google earth api a start point which I get back from Google map Api v3(I have lat and lng). The thing I want to do is give a location to Google Earth and it can automatically moved to street view level.

So far what I did can only move to ground level. The following code is how I try move Google Earth's camera

var lookAt = DS_ge.createLookAt('');
lookAt.setLatitude(myRoute.steps[0].path[0].lat());
lookAt.setLongitude(myRoute.steps[0].path[0].lng());
lookAt.setRange(1000.0); //default is 0.0
DS_ge.getView().setAbstractView(lookAt);

Is there any way to achieve the result like I move the pegman to the location I want and show the street view. I think there's a pegman function make it work but I can't find it. Any suggestion will be helpful thx :)

1条回答
爱情/是我丢掉的垃圾
2楼-- · 2020-04-11 14:21

To programmatically enter StreetView mode you need to add a gx:ViewOptions element to the LookAt element:

var lookAt = ge.createLookAt('');
// ... set your LookAt parameters
// don't forget default Altitude mode is ClampToGround
lookAt.setAltitudeMode(ge.ALTITUDE_RELATIVE_TO_GROUND)

// enable Street view option on ViewerOptions and add that to LookAt
var viewerOptions = ge.createViewerOptions('');
viewerOptions.setOption(ge.OPTION_STREET_VIEW, ge.OPTION_STATE_ENABLED);
lookAt.setViewerOptions(viewerOptions);

ge.getView().setAbstractView(lookAt);

To control whether the user can enter Street View using manual navigation controls, call

var navcontrol = ge.getNavigationControl();
navcontrol.setStreetViewEnabled(true);
查看更多
登录 后发表回答