【问题标题】:start virtual tour with gmaps v2 for android使用 gmaps v2 for android 开始虚拟之旅
【发布时间】:2014-05-03 06:57:46
【问题描述】:

有没有办法使用适用于 Android 的 google maps api v2 打开虚拟游览? (类似于此:https://www.google.com/maps/@37.772031,-122.432005,3a,75y,12.85h,79.63t/data=!3m5!1e1!3m3!1srR8mp3c5XZoAAAAGOphoBg!2e0!3e2

我想点击 gmap 中的一个地方并提供打开虚拟游览的可能性(以及其他信息)(即使在 web 视图中,但我如何创建上述链接?)

【问题讨论】:

    标签: java android google-maps virtual-tour


    【解决方案1】:

    Photo Sphere 是一项 Android 相机功能,可让您创建身临其境的360 degree panoramas - 类似于Street View。您可以拍摄一系列照片并自动将它们变成无缝的 360 degree panorama。然后,您可以轻松地与Google Maps 分享您的 Photo Sphere 照片。

    为了让 Google 地图显示在您的应用中,您应该将其包含在您的活动中:

    MainActivity.java
    public class MainActivity extends Activity {
    
        // Google Map
        private GoogleMap googleMap;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            try {
                // Loading map
                initilizeMap();
    
            } catch (Exception e) {
                e.printStackTrace();
            }
    
        }
    
        /**
         * function to load map. If map is not created it will create it for you
         * */
        private void initilizeMap() {
            if (googleMap == null) {
                googleMap = ((MapFragment) getFragmentManager().findFragmentById(
                        R.id.map)).getMap();
    
                // check if map is created successfully or not
                if (googleMap == null) {
                    Toast.makeText(getApplicationContext(),
                            "Sorry! unable to create maps", Toast.LENGTH_SHORT)
                            .show();
                }
            }
        }
    
        @Override
        protected void onResume() {
            super.onResume();
            initilizeMap();
        }
    
    }
    

    并在您的代码中包含一个marker,用于表示您想在哪里打开虚拟导览:

    // latitude and longitude
    double latitude = ;
    double longitude = ;
    
    // create marker
    MarkerOptions marker = new MarkerOptions().position(new LatLng(latitude, longitude)).title("Hello Maps ");
    
    // adding marker
    googleMap.addMarker(marker);
    

    然后更新它以根据当前提供的position coordinates 进行交互:

     public boolean onMarkerClick(Marker marker) {
    
      if(markerClicked){
    
       if(polyline != null){
        polyline.remove();
        polyline = null;
       }
    
       rectOptions.add(marker.getPosition());
       rectOptions.color(Color.RED);
       polyline = myMap.addPolyline(rectOptions);
      }else{
       if(polyline != null){
        polyline.remove();
        polyline = null;
       }
    
       rectOptions = new PolylineOptions().add(marker.getPosition());
       markerClicked = true;
      }
    
      return true;
     }
    
    }
    

    一旦将 Photo Sphere 制作为开放格式,任何人都可以在网络或移动设备上创建和查看它们,只需为此使用 Panorama Class/Interface

    // This listener will be called with information about the given panorama.
    OnPanoramaInfoLoadedListener infoLoadedListener =
      new OnPanoramaInfoLoadedListener() {
        @Override
        public void onPanoramaInfoLoaded(ConnectionResult result,
                                         Intent viewerIntent) {
            if (result.isSuccess()) {
                // If the intent is not null, the image can be shown as a
                // panorama.
                if (viewerIntent != null) {
                    // Use the given intent to start the panorama viewer.
                    startActivity(viewerIntent);
                }
            }
    
            // If viewerIntent is null, the image is not a viewable panorama.
        }
    };
    
    // Create client instance and connect to it.
    PanoramaClient client = ...
    ...
    
    // Once connected to the client, initiate the asynchronous check on whether
    // the image is a viewable panorama.
    client.loadPanoramaInfo(infoLoadedListener, panoramaUri);
    

    这将允许您将 Photo Sphere viewer 作为应用程序的一部分。

    【讨论】:

      猜你喜欢
      • 2013-04-26
      • 2014-11-16
      • 2022-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多