B4A Library GoogleMapsExtras

GoogleMapsExtras is an ongoing project to implement more of the Google Maps Android v2 classes in Basic4Android.

Currently the library allows you to create these objects:

Tutorials for each object will be uploaded to the Google Maps Android v2 tutorial thread.

Martin.
 

Attachments

  • GoogleMapsExtras_v1_71.zip
    59.6 KB · Views: 2,710
  • MapsForgeTileProvider_v1.01.zip
    173.1 KB · Views: 2,586
  • GoogleMapsExtras_v2_0_library_files.zip
    82.5 KB · Views: 3,011
Last edited:

arjian

Member
Licensed User
Longtime User
hi
I have a map with multiple polylines and would like to open a line-specific-infowindow when clicking on the lines (ofcurse it has a different content for each line)
Any help to show the infowindow on a polyline would really be appreciated.
 

warwound

Expert
Licensed User
Longtime User
hi
I have a map with multiple polylines and would like to open a line-specific-infowindow when clicking on the lines (ofcurse it has a different content for each line)
Any help to show the infowindow on a polyline would really be appreciated.

You need to know how to detect a click on a Polyline?
Or how to position an infowindow on a Polyline?

Or both?

Martin.
 

arjian

Member
Licensed User
Longtime User
i don't know how to capture a click event on a polyline object,in the other case i added a marker on small polygon and then by setting Alpha i have got what i needed but for the polylines i don't know how i can do something like that to capture click events on polylines and show infowindow with specified content .
 

warwound

Expert
Licensed User
Longtime User
The Polyline and Polygon objects have no built in click detection, you need to detect a click on the map and then work out whether or not that click is a click on one of your objects.

There's an interesting article that mat be of interest here: http://googlemapsapi.blogspot.co.uk...leMapsApiBlog+(Official+Google+Maps+API+Blog).

It might be a good idea for you to start a new thread with a title such as 'detect polyline click' - that's likely to get a response from other forum members.

Martin.
 

Wembly

Member
Licensed User
Longtime User
Hi Martin

Just looking at using the AnimateToBounds methods and note the description text is showing these methods as deprecated.

Do you have plans to updates these methods?

Thanks
 

warwound

Expert
Licensed User
Longtime User
Hi Martin

Just looking at using the AnimateToBounds methods and note the description text is showing these methods as deprecated.

Do you have plans to updates these methods?

Thanks

Those deprecated methods were added to GoogleMapsExtras before i added more complete support for the AnimateCamera methods and CameraUpdateFactory class.
See this post: http://www.b4x.com/android/forum/threads/googlemapsextras.26277/page-4#post-204919.
The AnimateCamera method(s) support all possible options, the AnimateToBounds supports a limited number of options.
I could have removed the AnimateToBounds method but left it there for backwards compatibility.

Martin.
 

Wembly

Member
Licensed User
Longtime User
Sorry Martin I didn't realise the CameraUpdateFactory class was actually being provided by your library (still a bit earlier in the day) - that makes sense now.

Thanks for the prompt response I'll look at using the new class now!

Cheers
 

CSP

Member
Licensed User
Longtime User
This library conflicts with the Gestures library, can no longer assign 'Points' to gestures when using both libraries...
 

warwound

Expert
Licensed User
Longtime User
This library conflicts with the Gestures library, can no longer assign 'Points' to gestures when using both libraries...

Can you give some more detail?
Do both libraries contain an object with the same name - Point?

Martin.
 

scsjc

Well-Known Member
Licensed User
Longtime User
hello some body know to create.... onMyLocationButtonClick() GoogleMapsExtras1.SetOnMyLocationButtonClickListener

i try with:

B4X:
            Dim OnMyLocationButtonClick As OnMyLocationButtonClickListener
            OnMyLocationButtonClick.Initialize("OnMyLocationButtonClick")
            If OnMyLocationButtonClick.IsInitialized Then
                GoogleMapsExtras1.SetOnMyLocationButtonClickListener(GoogleMap1,OnMyLocationButtonClick)
            Else
                Log("OnMyLocationButtonClick is not initialized - check that the Activity contains a Click callback Sub")
            End If


Sub OnMyLocationButtonClick_Click
    Log("clicked")
End Sub


but.... allways wrong ....
(sorry for my english)
 

warwound

Expert
Licensed User
Longtime User
Does your listener get initialized or do you see the message "OnMyLocationButtonClick is not initialized" in the log?

Martin.
 

scsjc

Well-Known Member
Licensed User
Longtime User
all is initialize and working, i try the:
OnMyLocationChangeListener1 >>> WORK
OnInfoWindowClickListener1 >>> WORK
OnMyLocationButtonClickListener >>> FAIL

the error are in this line:
GoogleMapsExtras1.SetOnMyLocationButtonClickListener(GoogleMap1,OnMyLocationButtonClick)


i see this log:



Parsing code. 0.43
Compiling code. 0.68
Compiling layouts code. 0.01
Generating R file. 0.79
Compiling generated Java code. Error
B4A line: 129
GoogleMapsExtras1.SetOnMyLocationButtonClickListener(GoogleMap1,OnMyLocationButtonClick)
javac 1.7.0_55
src\com\name\maps.java:715: error: cannot find symbol
mostCurrent._googlemapsextras1.SetOnMyLocationButtonClickListener((com.google.android.gms.maps.GoogleMap)(mostCurrent._googlemap1.getObject()),(com.google.android.gms.maps.GoogleMap.OnMyLocationButtonClickListener)(_onmylocationbuttonclick.getObject()));
^
symbol: class OnMyLocationButtonClickListener
location: class GoogleMap





some body have a sample with ..... SetOnMyLocationButtonClickListener
thanks a lot......
 
Last edited:

warwound

Expert
Licensed User
Longtime User
Maybe the version of the google-play-services.jar that's in your b4a additional libraries folder is not new enough?
Could it be a version that dates back to before the OnMyLocationButtonClickListener was added and so the class is not found?

Best to run the android SDK manager and update everything and then copy the google-play-services.jar file from the android SDK folder to your b4a additional libraries folder.
That'll ensure the version in your b4a additional libraries folder is up to date - now try to compile again.

Martin.
 

scsjc

Well-Known Member
Licensed User
Longtime User
Hello Martin,
now compile is ok, but in the moment execute i have a error because ...
object should first be initialized isnot initialize (OnMyLocationButtonClickListener)


is ok to inizialize like :

B4X:
Dim OnMyLocationButtonClickListener1 As OnMyLocationButtonClickListener
            OnMyLocationButtonClickListener1.Initialize("OnMyLocationButtonClickListener1")
            GoogleMapsExtras1.SetOnMyLocationButtonClickListener(GoogleMap1,OnMyLocationButtonClickListener1)



thanks a lot
juan carlos
 
Last edited:

warwound

Expert
Licensed User
Longtime User
You initialize the listener with the eventname: OnMyLocationButtonClickListener1.
So you must have a sub such as:

B4X:
Sub OnMyLocationButtonClickListener1_Click
    Log("Success!")
End Sub

Martin.
 

scsjc

Well-Known Member
Licensed User
Longtime User
yes.....but don't initialize.....grgrgr...... jajajaj i thing i'm stupid in any thing......
 

scsjc

Well-Known Member
Licensed User
Longtime User
Hello Martin,
i attach sample code with the error, can't fix.... i don't know why, can you test... (i think is possible from my librarys from basic4android)

B4X:
#Region  Project Attributes
    #ApplicationLabel: GoogleMapsPanorama
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
        #AdditionalRes: c:\android\android-sdk\extras\google\google_play_services\libproject\google-play-services_lib\res, com.google.android.gms

#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    Dim LastMapCenter As LatLng
    Dim LastMapZoom As Int
End Sub

Sub Globals
    Dim GoogleMap1 As GoogleMap
    Dim MapFragment1 As MapFragment
    Dim MapPanel As Panel
    Dim TileOverlay1 As TileOverlay
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Main")
    If MapFragment1.IsGooglePlayServicesAvailable = False Then
        ToastMessageShow("Google Play services not available.", True)
    Else
        If FirstTime Then
            LastMapCenter.Initialize(40.6443475,2.6305006)
            LastMapZoom=0
        End If
        MapFragment1.Initialize("MapFragment1", MapPanel)
    End If
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
    LastMapCenter=MapFragment1.GetMap.CameraPosition.Target
    LastMapZoom=MapFragment1.GetMap.CameraPosition.Zoom
End Sub

Sub MapFragment1_Ready
    Log("MapFragment1_Ready")
    GoogleMap1 = MapFragment1.GetMap
    If GoogleMap1.IsInitialized = False Then
        ToastMessageShow("Error initializing map.", True)
    Else
        '    set the map-type to none
        '    we do not want to load any of the built in tile sources
        'GoogleMap1.MapType=GoogleMap1.MAP_TYPE_NONE
        GoogleMap1.MapType=GoogleMap1.MAP_TYPE_NORMAL
     
        Dim GoogleMapsExtras1 As GoogleMapsExtras
        Dim TileOverlayOptions1 As TileOverlayOptions
        Dim UrlTileProvider1 As UrlTileProvider
     
        '    Url parameters are %1$d tileX, %2$d tileY, %3$d zoom
        '    my panorama tiles are all in a single directory and are named: <zoom>_<tileX>x<tileY>.jpg
     
        UrlTileProvider1.Initialize("http://162.221.184.24/tmp/wormegay_river_nar/%3$d_%1$dx%2$d.jpg", 256, 256)
        TileOverlayOptions1.Initialize
        TileOverlayOptions1.SetTileProvider(UrlTileProvider1)
        TileOverlay1=GoogleMapsExtras1.AddTileOverlay(GoogleMap1, TileOverlayOptions1)
     
        Dim Marker1 As Marker
        Marker1=GoogleMap1.AddMarker(40.6443475,2.0305006, "casa")
        Marker1=GoogleMap1.AddMarker(40.6443475,2.0805006, "1")
        Dim CameraPosition1 As CameraPosition
'        CameraPosition1.Initialize(LastMapCenter.Latitude, LastMapCenter.Longitude, LastMapZoom)
        CameraPosition1.Initialize(41.6443475,2.7305006, 15)
        GoogleMap1.AnimateCamera(CameraPosition1)

        'evento despues de click a home location buton
        Dim OnMyLocationButtonClickListener1 As OnMyLocationButtonClickListener
        OnMyLocationButtonClickListener1.Initialize("OnMyLocationButtonClickListener1")
        GoogleMapsExtras1.SetOnMyLocationButtonClickListener(GoogleMap1,OnMyLocationButtonClickListener1)
        GoogleMap1.MyLocationEnabled=True
        GoogleMap1.GetUiSettings.CompassEnabled=True


    End If
End Sub
Sub OnMyLocationButtonClickListener1_Click
Log("clicked")

End Sub
 

warwound

Expert
Licensed User
Longtime User
Just a guess, enable MyLocation before adding the listener?

B4X:
        'evento despues de click a home location buton
        GoogleMap1.MyLocationEnabled=True
        GoogleMap1.GetUiSettings.CompassEnabled=True
        Dim OnMyLocationButtonClickListener1 As OnMyLocationButtonClickListener
        OnMyLocationButtonClickListener1.Initialize("OnMyLocationButtonClickListener1")
        GoogleMapsExtras1.SetOnMyLocationButtonClickListener(GoogleMap1,OnMyLocationButtonClickListener1)
 

scsjc

Well-Known Member
Licensed User
Longtime User
somebody work the ... OnMyLocationButtonClickListener1_Click event ?????
i test this code but dont work....
have a error on ... not initialized OnMyLocationButtonClickListener

thanks !!!!!!



B4X:
#Region  Project Attributes
    #ApplicationLabel: GoogleMapsPanorama
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
        #AdditionalRes: c:\android\android-sdk\extras\google\google_play_services\libproject\google-play-services_lib\res, com.google.android.gms

#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    Dim LastMapCenter As LatLng
    Dim LastMapZoom As Int
End Sub

Sub Globals
    Dim GoogleMap1 As GoogleMap
    Dim MapFragment1 As MapFragment
    Dim MapPanel As Panel
    Dim TileOverlay1 As TileOverlay
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Main")
    If MapFragment1.IsGooglePlayServicesAvailable = False Then
        ToastMessageShow("Google Play services not available.", True)
    Else
        If FirstTime Then
            LastMapCenter.Initialize(40.6443475,2.6305006)
            LastMapZoom=0
        End If
        MapFragment1.Initialize("MapFragment1", MapPanel)
    End If
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
    LastMapCenter=MapFragment1.GetMap.CameraPosition.Target
    LastMapZoom=MapFragment1.GetMap.CameraPosition.Zoom
End Sub

Sub MapFragment1_Ready
    Log("MapFragment1_Ready")
    GoogleMap1 = MapFragment1.GetMap
    If GoogleMap1.IsInitialized = False Then
        ToastMessageShow("Error initializing map.", True)
    Else
        '    set the map-type to none
        '    we do not want to load any of the built in tile sources
        'GoogleMap1.MapType=GoogleMap1.MAP_TYPE_NONE
        GoogleMap1.MapType=GoogleMap1.MAP_TYPE_NORMAL
   
        Dim GoogleMapsExtras1 As GoogleMapsExtras
        Dim TileOverlayOptions1 As TileOverlayOptions
        Dim UrlTileProvider1 As UrlTileProvider
   
        '    Url parameters are %1$d tileX, %2$d tileY, %3$d zoom
        '    my panorama tiles are all in a single directory and are named: <zoom>_<tileX>x<tileY>.jpg
   
        UrlTileProvider1.Initialize("http://162.221.184.24/tmp/wormegay_river_nar/%3$d_%1$dx%2$d.jpg", 256, 256)
        TileOverlayOptions1.Initialize
        TileOverlayOptions1.SetTileProvider(UrlTileProvider1)
        TileOverlay1=GoogleMapsExtras1.AddTileOverlay(GoogleMap1, TileOverlayOptions1)
   
        Dim Marker1 As Marker
        Marker1=GoogleMap1.AddMarker(40.6443475,2.0305006, "casa")
        Marker1=GoogleMap1.AddMarker(40.6443475,2.0805006, "1")
        Dim CameraPosition1 As CameraPosition
'        CameraPosition1.Initialize(LastMapCenter.Latitude, LastMapCenter.Longitude, LastMapZoom)
        CameraPosition1.Initialize(41.6443475,2.7305006, 15)
        GoogleMap1.AnimateCamera(CameraPosition1)

      GoogleMap1.MyLocationEnabled=True
        GoogleMap1.GetUiSettings.CompassEnabled=True

        'evento despues de click a home location buton
        Dim OnMyLocationButtonClickListener1 As OnMyLocationButtonClickListener
        OnMyLocationButtonClickListener1.Initialize("OnMyLocationButtonClickListener1")
        GoogleMapsExtras1.SetOnMyLocationButtonClickListener(GoogleMap1,OnMyLocationButtonClickListener1)

    End If
End Sub
Sub OnMyLocationButtonClickListener1_Click
Log("clicked")

End Sub
 
Last edited:

Maxory

Member
Licensed User
Longtime User
Hello warwound,

i tried to use the LatLngBounds.Center function; but every time the log throws an error:


java.lang.NoSuchMethodError: com.google.android.gms.maps.model.LatLngBounds.getCenter
at uk.co.martinpearman.b4a.com.google.android.gms.maps.model.LatLngBounds.getCenter(LatLngBounds.java:33)

did i something wrong?

B4X:
Dim MarkerBounds As LatLngBounds=LLB1.Build
       
        Dim Marker2 As Marker
        Marker2 = gmap.AddMarker(MarkerBounds.Center.Latitude, MarkerBounds.Center.Longitude, "name")
 
Top