B4A Library PanoramaClient

PanoramaClient is part of the recent(ish) new Google Play Services API.
It enables you to view a 360 degree panorama using the device's built in Google Play Services panorama viewer.
Anyone that's used the new Photo Sphere feature of Android 4.2 will recognise what this library is capable of viewing.

There's an informative article that's worth a read here: New Google Maps Android API now part of Google Play services | Android Developers Blog.
And the official documentation for the PanoramaClient can be found here: PanoramaClient | Android Developers.

Here's the documentation for my b4a library:

PanoramaClient
Version: 1.00
  • PanoramaClient
    Events:
    • Connected
    • ConnectionFailed
    • Disconnected
    • PanoramaInfoLoaded (StatusCode As Int, ViewerIntent As Intent)
    Fields:
    • DEVELOPER_ERROR As Int
      The application is misconfigured.
    • INTERNAL_ERROR As Int
      An internal error occurred.
    • INVALID_ACCOUNT As Int
      The client attempted to connect to the service with an invalid account name specified.
    • LICENSE_CHECK_FAILED As Int
      The application is not licensed to the user.
    • NETWORK_ERROR As Int
      A network error occurred.
    • RESOLUTION_REQUIRED As Int
      Completing the connection requires some form of resolution.
    • SERVICE_DISABLED As Int
      The installed version of Google Play services has been disabled on this device.
    • SERVICE_INVALID As Int
      The version of the Google Play services installed on this device is not authentic.
    • SERVICE_MISSING As Int
      Google Play services is missing on this device.
    • SERVICE_VERSION_UPDATE_REQUIRED As Int
      The installed version of Google Play services is out of date.
    • SIGN_IN_REQUIRED As Int
      The client attempted to connect to the service but the user is not signed in.
    • SUCCESS As Int
      The connection was successful.
    Methods:
    • Connect
      Connects the client to Google Play services.
    • Disconnect
      Closes the connection to Google Play services.
    • Initialize (EventName As String)
    • IsConnected As Boolean
      Checks if the client is currently connected to the service, so that requests to other methods will succeed.
    • IsConnecting As Boolean
      Checks if the client is attempting to connect to the service.
    • LoadPanoramaInfo (Filepath As String)
      Loads information about a panorama.
      On completion raises the PanoramaInfoLoaded(StatusCode As Int, ViewerIntent As Intent) event.

PanoramaClient is not a View, think of it as simply a way to get an Intent which can be started to display a panorama.
On my Galaxy S3 my panoramas are displaying full screen - i see no way to embed a panorama into an activity.

And here's a sample b4a project:

B4X:
Sub Process_Globals
End Sub

Sub Globals
   Dim PanoramaClient1 As PanoramaClient
End Sub

Sub Activity_Create(FirstTime As Boolean)
   PanoramaClient1.Initialize("PanoramaClient1")
   PanoramaClient1.Connect
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
   If UserClosed Then
      PanoramaClient1.Disconnect
   End If
End Sub

Sub PanoramaClient1_Connected
   Log("PanoramaClient1_Connected")
   PanoramaClient1.LoadPanoramaInfo("mnt/extSdCard/cross_bank_road_panorama.jpg")
End Sub

Sub PanoramaClient1_ConnectionFailed
   Log("PanoramaClient1_ConnectionFailed")
End Sub

Sub PanoramaClient1_Disconnected
   Log("PanoramaClient1_Disconnected")
End Sub

Sub PanoramaClient1_PanoramaInfoLoaded(StatusCode As Int, ViewerIntent As Intent)
   Log("PanoramaClient1_PanoramaInfoLoaded")
   If ViewerIntent.IsInitialized Then
      StartActivity(ViewerIntent)
   Else
      Log("ViewerIntent not initialized")
      Select StatusCode
         Case PanoramaClient1.DEVELOPER_ERROR
            Log("DEVELOPER_ERROR")
         Case PanoramaClient1.INTERNAL_ERROR
            Log("INTERNAL_ERROR")
         Case PanoramaClient1.INVALID_ACCOUNT
            Log("INVALID_ACCOUNT")
         Case PanoramaClient1.LICENSE_CHECK_FAILED
            Log("LICENSE_CHECK_FAILED")
         Case PanoramaClient1.NETWORK_ERROR
            Log("NETWORK_ERROR")
         Case PanoramaClient1.RESOLUTION_REQUIRED
            Log("RESOLUTION_REQUIRED")
            '   this may be a recoverable error
            '   need to check on the forum for recent posts regarding
            '   the ConnectionResult startResolutionForResult(Activity activity, int requestCode) method
         Case PanoramaClient1.SERVICE_DISABLED
            Log("SERVICE_DISABLED")
         Case PanoramaClient1.SERVICE_INVALID
            Log("SERVICE_INVALID")
         Case PanoramaClient1.SERVICE_MISSING
            Log("SERVICE_MISSING")
         Case PanoramaClient1.SERVICE_VERSION_UPDATE_REQUIRED
            Log("SERVICE_VERSION_UPDATE_REQUIRED")
         Case PanoramaClient1.SIGN_IN_REQUIRED
            Log("SIGN_IN_REQUIRED")
         Case PanoramaClient1.SUCCESS
            Log("SUCCESS")
            '   i think if ViewerIntent is not initialized and the status code is SUCCESS then the panorama image is not a viewable panorama 
      End Select
   End If
End Sub

I have a photo sphere panorama on the root of my SD card, the code runs and gets an Intent from the PanoramaClient.
Starting this Intent displays my panorama in the built in panorama viewer.

I can't include a sample panorama image with the sample b4a project, even my lowest quality panorama is over 700KBs so far too big to attach to this post.
All is not lost though!
In order to use the PanoramaClient you need to download the latest version of the Google Play Services SDK and copy the google-play-services.jar library to your b4a additional libraries folder.
(You'll have already done this if you've used the b4a Google Maps library).
So download the Google Play Services SDK if you haven't already done so and locate where it's been downloaded to, on my computer it's located at:
C:\Users\martin\Programming\adt-bundle-windows\sdk\extras\google\google_play_services\libproject\google-play-services_lib\libs\google-play-services.jar
Copy this .jar library to your b4a additional libraries folder, now return to your SDK folder.
There is a java android sample PanoramaClient application and that sample contains an image you can use with my b4a PanoramaClient library.
This is the panaorama image location on my computer:
C:\Users\martin\Programming\adt-bundle-windows\sdk\extras\google\google_play_services\samples\panorama\res\raw\pano1.jpg

You'll need to copy the image to your device or add it to the demo project and then modify the path to the panorama:
B4X:
PanoramaClient1.LoadPanoramaInfo("path to pano1.jpg")
If you add the image to the demo using the File tab i think there is no way to create a path to the image in assets.
You'll have to copy the image from assets to the device's external memory.

Panorama fans might be interested in seeing photo spheres that others have submitted to Google: Contribute – Street View – Google Maps

Martin.

PanoramaClient is no longer working, the API it used in Google Play Services has been removed.
See post #7 in this thread for the newer PanoramaAPI library.
 
Last edited:

adastra

Member
Licensed User
Longtime User
Hi
I have downloaded your sample project but it doesn't seem to work . I downloaded your sample, copied google-play-services into my library folder. On compile it says .. waiting for IDE debugger to connect and then shows panoramaclient demo isn't responding. Do you want to close it ?

On pressing OK , the app crashes. Can you suggestion any tip ? I want to create a 360 degree or panoramic view app.
 

warwound

Expert
Licensed User
Longtime User
Great thanks :) would wait for the new API

Wait no longer...

I've attached version 0.10 of PanoramaAPI library and also a simple demo project.

B4X:
Sub Process_Globals
	Private PANORAMA_FILENAME As String="pano_20150313_140628.jpg"
End Sub

Sub Globals
	Dim PanoramaAPI1 As PanoramaAPI
End Sub

Sub Activity_Create(FirstTime As Boolean)
	'	** important: see manifest for required Google Play Services entry **
	
	'	copy the panorama to the file system
	'	it cannot be loaded from the assets folder
	If Not(File.Exists(File.DirDefaultExternal, PANORAMA_FILENAME)) Then
		File.Copy(File.DirAssets, PANORAMA_FILENAME, File.DirDefaultExternal, PANORAMA_FILENAME)
	End If
	
	PanoramaAPI1.Initialize("PanoramaAPI1")
	PanoramaAPI1.Connect
	
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
	PanoramaAPI1.Disconnect
End Sub

Sub PanoramaAPI1_ConnectionFailed(ConnectionResult1 As Int)
	Log("PanoramaAPI1_ConnectionFailed")
End Sub

Sub PanoramaAPI1_ConnectionSuccess
	Log("PanoramaAPI1_ConnectionSuccess")
	
	PanoramaAPI1.LoadPanoramaInfo(PanoramaAPI1.UriFromFile(File.DirDefaultExternal, PANORAMA_FILENAME))
	
End Sub

Sub PanoramaAPI1_ConnectionSuspended(SuspendedCause1 As Int)
	Log("PanoramaAPI1_ConnectionSuspended")
End Sub

Sub PanoramaAPI1_PanoramaInfoLoaded(PanoramaViewerIntent As Intent)
	Log("PanoramaAPI1_PanoramaInfoLoaded")
	If PanoramaViewerIntent.IsInitialized Then
		StartActivity(PanoramaViewerIntent)
	Else
		Log("PanoramaViewerIntent is not initialized")
	End If
End Sub

pano_20150313_140628.jpg is over 10MBs so i have not included it in the attached demo project.
You can download it from my server: http://b4a.martinpearman.co.uk/temp/pano_20150313_140628.jpg
Or you can use your own panoramic image.

I've tested the library on a Moto G and on a Galaxy K Zoom and it works as expected.
The Moto G has no sensor to detect the device orientation so compass mode doesn't work on the Moto G.
On my Galaxy K Zoom the sensor works and the panorama rotates as the device rotates.

I bet you will ask how to start the panorama viewer activity so it's already in 'compass mode' - i think thats what they call the mode where the panorama changes based on the device sensor.
I see nowhere in the API documentation where the panorama viewer can be started in compass mode - if you can find any information or code examples that show how to start the panorama viewer in compass mode let me know and i'll update the library.

Martin.
 

Attachments

  • PanoramaAPI_library_files_v0.10.zip
    9.3 KB · Views: 209
  • PanoramaAPIDemo.zip
    11.5 KB · Views: 202

NJDude

Expert
Licensed User
Longtime User
Regarding the compass, I see some messages in the logs about enabling and disabling the sensor, something like:

When tapping to disable:
B4X:
SensorService::listenerSensor++: mName = [email protected], eanble = 0, strlen(mName) = 44
and tapping to enable:
B4X:
registerListenerImpl: listener = [email protected], sensor = {Sensor name="BOSCH BMA250 3-axis Accelerometer", vendor="BOSCH", version=1, type=1, maxRange=39.2266, resolution=0.038307227, power=0.1, minDelay=10000}, delay = 20000, handler = null
 

adastra

Member
Licensed User
Longtime User
Superb ... It worked like a charm , though I don't have the so called compass mode on my mobile but with my finger navigation the image moved very smoothly . Great thanks for this wonderful help :)

Any help in regards to Virtual Reality too. I mean based on google cardboard I would want to display same image but split into two frames.
 

warwound

Expert
Licensed User
Longtime User
Any help in regards to Virtual Reality too. I mean based on google cardboard I would want to display same image but split into two frames.

That can't be possible with the PanoramaAPI as it is simply a way to show a panorama using the device's built in panorama viewer activity.
There's no way to display two panoramas (two activities) side by side using this library.

In your other thread i mentioned the StreetViewPanoramaView.
You can display 2 StreetViewPanoramaViews in a single activity - side by side if required.

But StreetViewPanoramaView can only display official Google StreetView imagery and panoramas which users have uploaded to Google+.
StreetViewPanoramaView cannot display a local panorama image - such as an image saved on the file system.

There are ways to display panoramas in a WebView and these panoramas could be local files on the file system.
And you could display 2 WebViews side by side.
But the WebView solution is far from optimal - it's javascript based, and relatively slow.

Are there any other android Views that are capable of displaying panoramas - Views which could be placed side by side in a single activity?
I did look at wrapping PanoramaGL into a b4a library a year back.
I ran the android demo on my mobile and it worked quite well - it also has built in support for different projection systems.
That was version 0.1, the current version is 0.2 beta.

Look on this page: https://code.google.com/p/panoramagl-android/downloads/list.
There's a demo apk download 'HelloPanoramaGL.apk', you could download and install that demo to see how well it works.

I might be able to find time to wrap (some of) PanoramaGL into a b4a library.
 

warwound

Expert
Licensed User
Longtime User
Now that i've looked at PanoramaGL in a bit more detail i see it has it's limitations.
https://code.google.com/p/panoramag...com/example/hellopanoramagl/MainActivity.java

  • Cubic panoramas limited to 1024x1024 pixels per face.
  • Spherical panoramas limited to 2024x1024 or 1024x512 pixels.
  • Cylindrical panoramas limited to 1024x1024 pixels.

Those dimensions are pretty small, on a modern android device with a decent sized screen PanoramaGL will not be capable of displaying high quality panoramas.
 

adastra

Member
Licensed User
Longtime User
Sorry warwound for very delayed response. Thanks for looking into PanoramaGL and giving your feedback. Did anyone find any alternate solution of displaying panorama in 2 views ?
 

warwound

Expert
Licensed User
Longtime User
No.
I have wrapped the PanoramaGL library but it displays panoramas full screen not as sizeable Views.
So no way to use it to display 2 panoramas side by side.
 
Top