2014-03-25 87 views

回答

12

Photo Sphere是一款Android攝像頭功能,可讓您創建身臨其境的360 degree panoramas - 類似於Street View。您可以拍攝一系列照片,並自動將它們變成無縫360 degree panorama。然後,您可以輕鬆地與Google Maps分享您的照片範圍。

enter image description here

爲了有顯示到你的應用程序的谷歌地圖,你應該包括它變成你的活動:

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

} 

enter image description here

而且還包括你的代碼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); 

enter image description here

然後更新相應地互動,提供的電流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; 
} 

} 

enter image description here

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

enter image description here

這將允許你有一個Photo Sphere viewer作爲你的應用程序的一部分。