Google Earth Api - programmatically enter StreetView mode

谁都会走 提交于 2019-12-04 04:28:18

问题


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:


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);


来源:https://stackoverflow.com/questions/15634742/google-earth-api-programmatically-enter-streetview-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!