How to display a MapView and a StreetView simultaneously?

后端 未结 3 1658
不思量自难忘°
不思量自难忘° 2020-12-20 06:43

I want to display a MapView that may be used to select a point to be displayed by StreetView in a separate area. I know that the API disallows multiple MapViews in a single

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-20 07:24

    You can load 360 degree panoramic Google street-view in your WebView.

    Try following activity in which both google-street-view and google-map can be navigated simultaneously in single Activity :

    public class StreetViewActivity extends Activity {
    
        private WebView webView;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            mappingWidgets();
        }
    
        private void mappingWidgets() {
    
            webView = (WebView) findViewById(R.id.webView);
            webView.getSettings().setJavaScriptEnabled(true);
    
            webView.getSettings().setLoadWithOverviewMode(true);
            webView.getSettings().setUseWideViewPort(true);
            webView.getSettings().setSupportZoom(false);  
    
    
            // If you want to load it from assets (you can customize it if you want)
            //Uri uri = Uri.parse("file:///android_asset/streetviewscript.html");
    
            // If you want to load it directly
            Uri uri = Uri.parse("https://google-developers.appspot.com/maps/documentation/javascript/examples/full/streetview-simple");
            webView.loadUrl(uri.toString());
        }
    }
    

    You can place this as static HTML page in assets folder of your application and then you can modify it's java-script according to your needs using Google street-view API.

    Here I am posting sample streetviewscript.html that you can put in assets folder of your application and customize it according to your needs :

    
    
      
        
        Google Maps JavaScript API v3 Example: Street View Layer
        
        
        
      
      
        

    Edit : For simultaneously navigating two street views, load following HTML from assets :

    
    
      
        
        Google Maps JavaScript API v3 Example: Street View Events
    
        
        
        
        
      
      
    
        

提交回复
热议问题