Android Tutorial Google Maps Android v2 tutorial

Discussion in 'Tutorials & Examples' started by Erel, Dec 18, 2012.

Thread Status:
Not open for further replies.
  1. Erel

    Erel Administrator Staff Member Licensed User

    Currently there is no DragEnd event.

    You can update the contents by setting the Snippet property. This will set the "second line":
    Code:
    Dim m As Marker = gmap.AddMarker(3615"Hello!!!")
    m.Snippet = 
    "second line"
     
  2. warwound

    warwound Expert Licensed User

    :signOops: Demo code removed as the CameraChange event is already supported!

    Martin.
     
    Last edited: Feb 21, 2013
  3. Erel

    Erel Administrator Staff Member Licensed User

  4. warwound

    warwound Expert Licensed User

    :signOops: that was an epic update then!

    I'll remove the OnCameraChangeListener from GoogleMapsExtras and update related posts so as to avoid any confusion.

    Martin.
     
    Last edited: Feb 21, 2013
  5. yamskie19

    yamskie19 New Member

    sir

    sir i cant understand the instructions in number 2.5 and 3.. what attached file will i download? and why is it that i dont have that kind of image in your screenshot in number 3?
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    For some reason you appear as an unlicensed user in the forum. Please contact support@basic4ppc.com in order to fix it.
     
  7. warwound

    warwound Expert Licensed User

    GoogleMapsExtras now supports polygons with holes.

    Here's a code example that shows a polygon around my hometown, i have used the new holes support to create a hole in the polygon where the local docks are located:

    Code:
    Sub Process_Globals
    End Sub

    Sub Globals
        
    Dim MapFragment1 As MapFragment
        
    Dim GoogleMap1 As GoogleMap
        
    Dim MapPanel As Panel
       
    Dim Polygon1 As Polygon
    End Sub

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

    Sub MapFragment1_Ready
        
    Log("MapFragment1_Ready")
        GoogleMap1 = MapFragment1.GetMap
        
    If GoogleMap1.IsInitialized = False Then
            
    ToastMessageShow("Error initializing map."True)
        
    Else
          GoogleMap1.MapType=GoogleMap1.MAP_TYPE_NORMAL
          
          
    Dim GoogleMapsExtras1 As GoogleMapsExtras
          
    Dim PolygonOptions1 As PolygonOptions
          
          
    Dim PolygonCoords() As Double=Array As Double(52.76670.393152.76370.384252.75950.386152.75700.386752.75230.387552.74800.391852.75040.396852.75150.400052.75320.400752.75500.402652.75810.401152.76000.397252.76400.400552.76670.3931)
          
    Dim PolygonPoints As List=CoordsToLatLngList(PolygonCoords)
          
          
    Dim HoleCoords() As Double=Array As Double(52.758440.3922752.759260.3954652.759830.3947752.760450.3954052.760410.3958352.762870.3976752.763320.3959852.760840.3942052.760620.3949652.759940.3945352.759950.3940152.759280.3917352.758440.39227)
          
    Dim HolePoints As List=CoordsToLatLngList(HoleCoords)
          
          PolygonOptions1.Initialize
          PolygonOptions1.AddHole(HolePoints)
          PolygonOptions1.AddPoints(PolygonPoints)   
    '   version 1.01 requires AddPolygonPoints to be used as the PolygonPoints property is now read-only
          PolygonOptions1.FillColor=Colors.ARGB(12825500)
          
    '   PolygonOptions1.PolygonPoints=PolygonPoints version 1.00 property PolygonPoints is now read-only
          PolygonOptions1.StrokeColor=Colors.Black
          PolygonOptions1.StrokeWidth=
    2
          
          Polygon1=GoogleMapsExtras1.AddPolygon(GoogleMap1, PolygonOptions1)
          
            
    Dim CameraPosition1 As CameraPosition
            CameraPosition1.Initialize(
    52.758110.391213)
            GoogleMap1.AnimateCamera(CameraPosition1)
        
    End If
    End Sub

    Sub CoordsToLatLngList(PolygonCoords() As Double) As List
       
    Dim PolygonCoordsCount As Int=PolygonCoords.Length
       
    Dim LatLngList As List
       LatLngList.Initialize
       
    Dim i As Int
       
    For i=0 To PolygonCoords.Length-2 Step 2
          
    Dim LatLng1 As LatLng
          LatLng1.Initialize(PolygonCoords(i), PolygonCoords(i+
    1))
          LatLngList.Add(LatLng1)
       
    Next
       
    Return LatLngList
    End Sub

    Sub RemoveButton_Click
       Polygon1.Remove
    End Sub

    Sub VisibilityButton_Click
       Polygon1.Visible=
    Not(Polygon1.Visible)
    End Sub
    If you are currently using version 1.00 of GoogleMapsExtras and it's Polygon object please read the thread linked to above - it mentions some syntax changes in the PolygonOptions object.

    Martin.
     

    Attached Files:

  8. ErickAsas

    ErickAsas Member Licensed User

    Hi Erel,

    Will there be support on this in the near future? I need to monitor this event when the user stops dragging the marker.

    Can you possibly give me the code to monitor this event using other methods?

    Thanks in advance.

    Erick
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread for this request in the wishlist forum.
     
  10. warwound

    warwound Expert Licensed User

    GoogleMapExtras now adds support for the OnMarkerDragListener.

    You can detect Drag, DragEnd and DragStart events on your draggable Markers:

    Code:
    Sub Process_Globals

    End Sub

    Sub Globals
        
    Dim MapFragment1 As MapFragment
        
    Dim GoogleMap1 As GoogleMap
        
    Dim MapPanel As Panel
       
    Dim Label1 As Label
    End Sub

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

    Sub MapFragment1_Ready
        
    Log("MapFragment1_Ready")
        GoogleMap1 = MapFragment1.GetMap
        
    If GoogleMap1.IsInitialized = False Then
            
    ToastMessageShow("Error initializing map."True)
        
    Else
          GoogleMap1.MapType=GoogleMap1.MAP_TYPE_NORMAL
          
          
    Dim Coords() As Double=Array As Double(52.76670.393152.74800.391852.75500.402652.76670.3931)
          
    Dim i As Int
          
    For i=0 To Coords.Length-2 Step 2
             
    Dim Marker1 As Marker
             Marker1=GoogleMap1.AddMarker(Coords(i), Coords(i+
    1), "Marker #"&i)
             Marker1.Draggable=
    True
          
    Next
          
          
    Dim GoogleMapsExtras1 As GoogleMapsExtras
          
          
    Dim OnMarkerDragListener1 As OnMarkerDragListener
          OnMarkerDragListener1.Initialize(
    "OnMarkerDragListener1")
          
          
    If OnMarkerDragListener1.IsInitialized Then
             GoogleMapsExtras1.SetOnMarkerDragListener(GoogleMap1, OnMarkerDragListener1)
          
    Else
             
    Log("OnMarkerDragListener1 is not initialized - check that the Activity contains at least one callback Sub")
          
    End If
          
            
    Dim CameraPosition1 As CameraPosition
            CameraPosition1.Initialize(
    52.758110.391213)
            GoogleMap1.AnimateCamera(CameraPosition1)
        
    End If
    End Sub

    Sub OnMarkerDragListener1_Drag(Marker1 As Marker)
       
    Log("OnMarkerDragListener1_Drag")
       Label1.Text=Marker1.Title&
    " : "&Marker1.Position
    End Sub

    Sub OnMarkerDragListener1_DragEnd(Marker1 As Marker)
       
    Log("OnMarkerDragListener1_DragEnd")
       Label1.Text=Marker1.Title&
    " : "&Marker1.Position
    End Sub

    Sub OnMarkerDragListener1_DragStart(Marker1 As Marker)
       
    Log("OnMarkerDragListener1_DragStart")
       Label1.Text=Marker1.Title&
    " : "&Marker1.Position
    End Sub
    As with previous example code, you will need to modify my example with a correct API key.

    Martin.
     

    Attached Files:

  11. ErickAsas

    ErickAsas Member Licensed User

    Wow, many thanks Martin. You're a lifesaver.
     
  12. Erel

    Erel Administrator Staff Member Licensed User

    Thanks Martin. :sign0188:
     
  13. spyboy79

    spyboy79 Member Licensed User

    Hi Erel,
    I started "play" with maps, but my and your test app on my Galaxy S 2.3.6 original goes crash with this error:

    Code:
    ** Activity (main) Create, isFirst = true **
    main_activity_create (java line: 
    241)
    java.lang.NoSuchMethodError: android.app.Activity.getFragmentManager
       at anywheresoftware.b4a.objects.MapFragmentWrapper.Initialize(MapFragmentWrapper.java:
    115)
       at b4a.maps.example.main._activity_create(main.java:
    241)
       at java.lang.reflect.Method.invokeNative(Native Method)
       at java.lang.reflect.Method.invoke(Method.java:
    507)
       at anywheresoftware.b4a.BA.raiseEvent2(BA.java:
    167)
       at b4a.maps.example.main.afterFirstLayout(main.java:
    85)
       at b4a.maps.example.main.access$
    100(main.java:16)
       at b4a.maps.example.main$WaitForLayout.run(main.java:
    72)
       at android.os.Handler.handleCallback(Handler.java:
    587)
       at android.os.Handler.dispatchMessage(Handler.java:
    92)
       at android.os.Looper.loop(Looper.java:
    130)
       at android.app.ActivityThread.main(ActivityThread.java:
    3687)
       at java.lang.reflect.Method.invokeNative(Native Method)
       at java.lang.reflect.Method.invoke(Method.java:
    507)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:
    842)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:
    600)
       at dalvik.system.NativeStart.main(Native Method)
    ** 
    Activity (main) Create, isFirst = true **
    main_activity_create (java line: 
    241)
    java.lang.NoSuchMethodError: android.app.Activity.getFragmentManager
       at anywheresoftware.b4a.objects.MapFragmentWrapper.Initialize(MapFragmentWrapper.java:
    115)
       at b4a.maps.example.main._activity_create(main.java:
    241)
       at java.lang.reflect.Method.invokeNative(Native Method)
       at java.lang.reflect.Method.invoke(Method.java:
    507)
       at anywheresoftware.b4a.BA.raiseEvent2(BA.java:
    167)
       at b4a.maps.example.main.afterFirstLayout(main.java:
    85)
       at b4a.maps.example.main.access$
    100(main.java:16)
       at b4a.maps.example.main$WaitForLayout.run(main.java:
    72)
       at android.os.Handler.handleCallback(Handler.java:
    587)
       at android.os.Handler.dispatchMessage(Handler.java:
    92)
       at android.os.Looper.loop(Looper.java:
    130)
       at android.app.ActivityThread.main(ActivityThread.java:
    3687)
       at java.lang.reflect.Method.invokeNative(Native Method)
       at java.lang.reflect.Method.invoke(Method.java:
    507)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:
    842)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:
    600)
       at dalvik.system.NativeStart.main(Native Method)
    Any idea?
     
  14. warwound

    warwound Expert Licensed User

    You mean Gingerbread 2.3.6 do you?

    You need a minimum Android version od 3.0 to use this library - see the first post in this thread.

    Martin.
     
  15. Erel

    Erel Administrator Staff Member Licensed User

    See the first post:
     
  16. spyboy79

    spyboy79 Member Licensed User

    aaahhh ok, I understood the api level, sorry :sign0013:
     
  17. ErickAsas

    ErickAsas Member Licensed User

    How To Get The Map Center LatLng

    Hi Erel/Martin,

    Can you help me with this?

    In Javascript, this used to be Map.getCenter()...
     
  18. warwound

    warwound Expert Licensed User

    I think you want the GoogleMap CameraPosition property.
    Then you can get the CameraPosition Target property.

    Martin.
     
  19. ErickAsas

    ErickAsas Member Licensed User

    I tried to get the camera target property when I move the map away from the initial cp position. The camera target property does not change when you move the map.
     
  20. warwound

    warwound Expert Licensed User

    Seems to work for me:

    Code:
    Sub Process_Globals

    End Sub

    Sub Globals
        
    Dim MapFragment1 As MapFragment
        
    Dim GoogleMap1 As GoogleMap
        
    Dim MapPanel As Panel
       
    Dim Polygon1 As Polygon
       
    Dim LocationLabel As Label
    End Sub

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

    Sub MapFragment1_Ready
        
    Log("MapFragment1_Ready")
        GoogleMap1 = MapFragment1.GetMap
        
    If GoogleMap1.IsInitialized = False Then
            
    ToastMessageShow("Error initializing map."True)
        
    Else
          GoogleMap1.MapType=GoogleMap1.MAP_TYPE_NORMAL
            
    Dim CameraPosition1 As CameraPosition
            CameraPosition1.Initialize(
    52.6890.77010)
            GoogleMap1.AnimateCamera(CameraPosition1)
        
    End If
    End Sub

    Sub LocationButton_Click
       LocationLabel.Text=GoogleMap1.CameraPosition.Target
    End Sub
    Pan the map and then click LocationButton, repeat a few times, it shows a different map center.

    Martin.
     

    Attached Files:

Thread Status:
Not open for further replies.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice