Android Tutorial (old) Google Maps Android v2 tutorial

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

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

    cthomas4579 Member Licensed User

    Having the same problem with this.. It doesn't appear in the right side under referenced libraries. Perform a refresh and still nothing.. Restart the IDE still nothing.

    Any ideas?

    Google-play-services.jar is copied to the libraries folder of b4 and paths are set
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Please do not post duplicate questions. See my answer in the other thread.
     
  3. denik

    denik Member Licensed User

    Hi, Erel
    Please, write an example of using MarkerClick event of MapFragment
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    You just need to implement the sub:
    Code:
    Sub Map_MarkerClick (SelectedMarker As MarkerAs Boolean
       
    Log(SelectedMarker.Title)
       
    Return True
    End Sub
     
    GMan likes this.
  5. denik

    denik Member Licensed User

    Hi Erel
    Can I determine the screen coordinates of Marker object?
     
  6. warwound

    warwound Expert Licensed User

    GoogleMapsExtras allows you to use the Projection object.

    You can get a LatLng from a screen coordinate and vice versa with it's FromScreenLocation and ToScreenLocation methods.

    Unfortunately both these methods require a Point object and i think b4a has no native support for the Point object.

    This is where i sometimes wonder if it'd be handy to have a database or even just a plain list of all Android classes that have currently been wrapped and can therefore be used in b4a - it'd save me wrapping a class that has already been wrapped in another library.

    Anyway, i'll update GoogleMapsExtras a bit later so that you can use it's FromScreenLocation and ToScreenLocation methods.

    Martin.
     
  7. warwound

    warwound Expert Licensed User

    :sign0161:

    What am i saying - i've already added a Point wrapper to the GoogleMapsExtras library!

    Must be time for a rest.

    So you can in fact create a LatLng and then use the Projection method ToScreenLocation to get a Point which represents the current screen position of that LatLng.

    Martin.
     
  8. denik

    denik Member Licensed User

    Hi, Martin
    When I add GoogleMapsExtras library (even in empty project) and insert the only string
    Dim p As Point
    it is
    java.lang.RuntimeException: Object should first be initialized (Point).
     
  9. warwound

    warwound Expert Licensed User

    I've now fixed the bug where Point could not be initialized, get the updated version of GoogleMapsExtras from here: http://www.basic4ppc.com/forum/addi...pdates/26277-googlemapsextras.html#post152004.

    And here's an example that logs the screen coordinates each time the map position changes:

    Code:
    Sub Process_Globals

    End Sub

    Sub Globals
        
    Dim GoogleMap1 As GoogleMap
       
    Dim GoogleMapsExtras1 As GoogleMapsExtras
        
    Dim MapFragment1 As MapFragment
        
    Dim MapPanel As Panel
       
    Dim Projection1 As Projection
    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
            
    Dim CameraPosition1 As CameraPosition
            CameraPosition1.Initialize(
    520.756)
            GoogleMap1.AnimateCamera(CameraPosition1)
        
    End If
    End Sub

    Sub MapFragment1_CameraChange (Position As CameraPosition)
       Projection1=GoogleMapsExtras1.GetProjection(GoogleMap1)
       
       
    Dim Point1 As Point
       Point1=Projection1.ToScreenLocation(Position.Target)
       
       
    Log("LatLng1: "&Position.Target)
       
    Log("Point1: "&Point1)
       
    End Sub
    On my Novo ElfII tablet that always logs (512, 246), the documentation states:

    So i'm not sure how to use these coordinates, i'll have to leave you to experiment.

    Martin.
     

    Attached Files:

    Powie likes this.
  10. Bart Kerver

    Bart Kerver New Member Licensed User

    Android 2 and google maps

    HI,

    I'm aware of "this library requires Android 3+" and it works fine on my tablet, but was wondering how the Google Maps (the app) on a Android 2 (gingerbread - Samsung galaxy2) seems to be working fine.

    Is this a B4A library issue or does Google Maps (the app) work a different way on Android 2x?

    Kind regards,
    Bart
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    This library wraps MapFragment which is only supported by Android 3+. There is another API named SupportMapFragment that is based on a "support library" for backwards compatibility (as Fragments were not supported in Android 2).

    There are some known issues with SupportMapFragment.
     
  12. desof

    desof Well-Known Member Licensed User

    followed to the letter and I get this error I am doing wrong?

    followed to the letter and I get this error I am doing wrong?


    Parsing code. 0.00
    Compiling code. 0.20
    Compiling layouts code. 0.02
    Generating R file. 0.45
    Compiling generated Java code. Error
    B4A line: 44
    gmap.AnimateCamera(cp)
    javac 1.7.0_17
    src\b4a\example\main.java:338: error: package com.google.android.gms.maps.model does not exist
    mostCurrent._gmap.AnimateCamera((com.google.android.gms.maps.model.CameraPosition)(_cp.getObject()));
    ^
    1 error
     
  13. Erel

    Erel Administrator Staff Member Licensed User

  14. tpakis

    tpakis Active Member Licensed User

    Erel is it very difficult to make a second library that wraps SupportMapFragment? I have seen google maps v2 running on 2.2 devices. Nearly 60% of my app users according to store still use 2.2-2.3
     
  15. Erel

    Erel Administrator Staff Member Licensed User

    If you like I can upload the code and you can try to modify it as needed (I actually think that the code should be already available in this thread somewhere).
     
  16. AlteregoHR

    AlteregoHR Member Licensed User

    Hello to all,
    This is my first post :)
    I just bought B4a and I am trying Google maps api. I went through all the steps successfully except adding lines to manifest editor.
    I copied the lines that go to the manifest and added key from google.
    Now, when compiling I get:
    Failure [INSTALL_PARSE_FAILED_MANIFEST_MALFORMED] :sign0085:

    Edit: The answer was in another Thread : Package name with non-lowercase letter
     
    Last edited: Apr 28, 2013
  17. tpakis

    tpakis Active Member Licensed User

    You mean the java code for the library? Yes why not (didn't find it in the thread).
     
  18. sioconcept

    sioconcept Active Member Licensed User

  19. Erel

    Erel Administrator Staff Member Licensed User

    The library code is attached.

    It is currently not exposed in this library. Try this library: GoogleMapsExtras
     

    Attached Files:

  20. warwound

    warwound Expert Licensed User

    I have updated GoogleMapsExtras adding support for the OnInfoWindowClickListener.

    Here's some example code:

    Code:
    Sub Process_Globals

    End Sub

    Sub Globals
        
    Dim GoogleMap1 As GoogleMap
       
    Dim Label1 As Label
        
    Dim MapFragment1 As MapFragment
        
    Dim MapPanel As Panel
    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/2))
             Marker1.Draggable=
    True
          
    Next
          
          
    Dim GoogleMapsExtras1 As GoogleMapsExtras
          
          
    Dim OnInfoWindowClickListener1 As OnInfoWindowClickListener
          OnInfoWindowClickListener1.Initialize(
    "OnInfoWindowClickListener1")
          
          
    If OnInfoWindowClickListener1.IsInitialized Then
             GoogleMapsExtras1.SetOnInfoWindowClickListener(GoogleMap1, OnInfoWindowClickListener1)
          
    Else
             
    Log("OnInfoWindowClickListener1 is not initialized - check that the Activity contains a Click callback Sub")
          
    End If
          
            
    Dim CameraPosition1 As CameraPosition
            CameraPosition1.Initialize(
    52.758110.391213)
            GoogleMap1.AnimateCamera(CameraPosition1)
        
    End If
    End Sub

    Sub OnInfoWindowClickListener1_Click(Marker1 As Marker)
       
    Log("OnInfoWindowClickListener1_Click")
       Label1.Text=Marker1.Title&
    " : "&Marker1.Position
    End Sub
    3 Markers are added to the map, a click on a Marker shows an infowindow and a click on an infowindow causes the OnInfoWindowClickListener1_Click Sub to be called and a Label displays the position and title of the Marker that the infowindow was opened on.

    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