Android Question Adding draggable Markers to a map

Roger Daley

Well-Known Member
Licensed User
Hi All,

I am trying to come to grips with Markers Etc. Currently I have a MapViewer stripped out of Klaus's GPSExample [I started with "GPSExample" then realized my final objective will have no need of GPS]
I have come to the stage where I need to add two draggable makers to the map in ActivityCreate. They will always be present. They each have an individual icon to distinguish them.

I have read and re-read everything I can find on the forum, Wiki, Warwounds DraggableMarker example etc. Lots of info and examples re: Webview, WebviewExtras, OSMDroid Etc. However I find that with each that I have walked in to the middle of a conversation and have missed the point.

Can anyone provide the explanation for the "Totally Ignorant" as to how to add two markers [individual icons] to a map created in Webview.


Thanks in advance
Regards Roger
 

eurojam

Well-Known Member
Licensed User

Roger Daley

Well-Known Member
Licensed User
Erel,

Answer in two parts.

1. Because Kauls didn't use it as the map viewer in his GPSExample which is where I started.
2. Probably because I don't know what I am doing.

Are you suggesting I should dump what I have and start afresh with Google Maps SDK? If so, can you please suggest a starting point.

Regards Roger
 

Roger Daley

Well-Known Member
Licensed User
Thanks Erel,

I've had a quick look and this should keep me occupied for some extended time, but a definite path to follow.
Looking back I think I had been confused with different paths in the evolution of map viewing.


Regards Roger
 

eurojam

Well-Known Member
Licensed User
Roger, here is a small example with a google map and one Marker which you can drag. Please follow the instructions how to setup the google Map lib (http://www.b4x.com/android/forum/threads/google-maps-android-v2-tutorial.24415/#post-141316)

B4X:
#Region  Project Attributes
    #ApplicationLabel: GoogleMapDemo
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

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

#AdditionalRes: C:\Programme\Android\android-sdk\extras\google\google_play_services\libproject\google-play-services_lib\res, com.google.android.gms
Sub Process_Globals
    Dim GoogleMapsExtras1 As GoogleMapsExtras
End Sub

Sub Globals
   Dim mFragment As MapFragment
   Dim gmap As GoogleMap

   Dim MapPanel As Panel
   Dim cp As CameraPosition

    'Dim GoogleMapsExtras1 As GoogleMapsExtras
End Sub

Sub Activity_Create(FirstTime As Boolean)
   MapPanel.Initialize("")
   Activity.AddView(MapPanel, 0, 0, 100%x, 100%y)
   If mFragment.IsGooglePlayServicesAvailable = False Then
      ToastMessageShow("Google Play services not available.", True)
   Else
      mFragment.Initialize("Map", MapPanel)
   End If
End Sub
Sub Map_Ready
   Log("map ready")
   gmap = mFragment.GetMap
   If gmap.IsInitialized = False Then
        ToastMessageShow("Error initializing map.", True)
   Else
        Dim MarkerOptions1 As MarkerOptions
        MarkerOptions1.Initialize

        Dim tmpMarker As Marker
        MarkerOptions1.Draggable(True)  
        MarkerOptions1.Position2(64.79619, 18.3980).Snippet("pkt").Title("1")
        tmpMarker=GoogleMapsExtras1.AddMarker(gmap, MarkerOptions1)
      
        Dim markerDragListener As OnMarkerDragListener
        markerDragListener.Initialize("markerDragListener")
        GoogleMapsExtras1.SetOnMarkerDragListener(gmap,markerDragListener)

        Dim cp As CameraPosition
        cp.Initialize(64, 18, gmap.CameraPosition.Zoom)
        gmap.AnimateCamera(cp)
   End If
End Sub
Sub markerDragListener_Drag(Marker1 As Marker)
      Log("Drag")
End Sub

Sub markerDragListener_DragEnd(Marker1 As Marker)
      Log("DragEnd")

End Sub

Sub markerDragListener_DragStart(Marker1 As Marker)
      Log("DragStart")
End Sub
Hope this helps
stefan
 

Roger Daley

Well-Known Member
Licensed User
No worries Klaus,

I've slowly caught on that the many things that I found on the forum were different stages of evolution.
Going through your GPS example has been a great learning experience for me. Several things have been noted for use in the future.

Thanks for your help.

Regards Roger
 

Roger Daley

Well-Known Member
Licensed User
Hi All

Back again. I've tried using the code kindly posted by Stefan [Post#8]

Re-Installed SDK
Installed Google Play Services
Followed the "Google Maps Android v2 tutorial"
Followed the "Google Play Services - Installation & Tips"
Copied files to different locations
Stumbled through the manifest editor
Created API key

Etc. [It takes a group like the Google Team of computer guru's to make something this convoluted]

The result is, when I try to run the code [Release or Debug] I get "Google Play services not available". No clues as to why.
Obviously I have missed something, done something wrong.
I have uploaded the project zip in desparation, if someone can tell me where I have gone wrong I would be most grateful otherwise I will forget about Google Maps.


Regards Roger
 

Attachments

Erel

Administrator
Staff member
Licensed User
[It takes a group like the Google Team of computer guru's to make something this convoluted]
That's correct. However once you try to implement in app purchases or push notifications in iOS then you see that it can be worse ;)

Can you post the message from the logs?

Are you testing it on a real device? It will not work on an emulator.
 

eurojam

Well-Known Member
Licensed User
Hi Roger,
I have tried your project with my sign key / package name and it worked. I've changed the additional res to:
B4X:
'that was your Res
'#AdditionalRes: C:\Program Files\Android\android-sdk\extras\google\google_play_services\libproject\google-play-services_lib\res
'but it should be like this
#AdditionalRes: C:\Programme Files\Android\android-sdk\extras\google\google_play_services\libproject\google-play-services_lib\res, com.google.android.gms
then you have to do the following things:
register your app with the sha1 key produced from your keyfile at: https://console.developers.google.com
this should be a line like this(sha1;package name):
xx:C6:79:xx:05:37:26:73:xx:E7:71:44:2B:xx:49:C3:5A:xx:26:27;horsetrailer.B4A.AntennaBearingTool
finally run your app (debug mode or release mode) with your registered sign key

stefan
 

Roger Daley

Well-Known Member
Licensed User
Erel/Stefan

Thanks for you help.
Erel has hit part of the problem. I was using an emulator, when I use a real device the program loads but with a white screen, no map, nothing in the log.
I think this has something to do with Google Maps API not being enabled in the developer console. I will research this tomorrow, it has been a long day and is time to move away from the keyboard.

Thanks again
Roger
 

Roger Daley

Well-Known Member
Licensed User
Thanks Erel,

This is much appreciated. The good news is that I managed to get the Demo working earlier today. That is after fixing a couple of my errors and being confused by Googles
ambiguous reference to "enable the API" following "Create an API" when they meant "enable the Google Maps API".

Now that I have a base on which to work I'll start to tinker with the demo code in between my domestic duties. :(
Stand by for the next question, probably in a new thread.

Regards Roger
 
Top