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. AlteregoHR

    AlteregoHR Member Licensed User

    Hello to all,
    Is there any chance that someone can make example of:
    1. Adding markers to the map with button click after the map was initialised and frst set of marks were added during first setup. ( I want to add few marks form file or database on button click event, but keep the old ones. )
    2. Keeping map in the same location after the screen rotation?

    I am new to this and tryinig to figure how to do that but I just cant do it :BangHead:

    Thanks for helping :sign0104:
     
  2. adrianstanescu85

    adrianstanescu85 Active Member Licensed User

    Center the gmap to the center of the panel

    Hello all

    I'm having a rather simple (I guess!!) problem, I just implemented google maps on my app (I'm using a Samsung Galaxy Note 10.1 tablet) and the actual map is contained inside a panel (called Panel1). This panel is somewhere on the right part of the screen, the main idea here is that it is not placed in the very center of the screen.

    I turned on the GPS, got the current coordinates and animated the camera to those coordinates with a zoom of 15, and what it happens so far is that the map puts that particular target IN THE CENTER OF THE TABLET SCREEN and then zooms, instead of placing the target IN THE CENTER OF THE PANEL THAT CONTAINS THE MAP and then have the zoom. So even if the map is in fact contained within the panel, if the panel has for instance its edge close to the middle of the screen, I can see almost nothing out of my target.

    How can I correct this? Please let me know, anyone.

    Thank you!
     
  3. sioconcept

    sioconcept Active Member Licensed User

    Oo Man, i love you ! Thanks for sharing and speed !!!
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    @adrianstanescu85 not sure about this. Might be a bug in Google maps API.

    @AlteregoHR, this line adds a marker:
    Code:
    Dim m As Marker = gmap.AddMarker(3615"Hello!!!")
    About the position. Add a process global variable of type CameraPosition. In Activity_Pause you should assign gmap.CameraPosition to this variable. Later in Map_Ready you should check whether this variable is initialized and if yes call gmap.MoveCamera(...).
    Put it in Button_Click event.
     
  5. adrianstanescu85

    adrianstanescu85 Active Member Licensed User

    Actually what I did find is that when writing the code,
    Panel1.AddView(MapPanel, 0, 0, 100%x, 100%y)
    that 100% is true NOT for the Panel object itself but for the visible part of the SCREEN.

    This is true for other objects as well that use AddView.

    Is this supposed to be this way, or have I just found a bug?
     
  6. warwound

    warwound Expert Licensed User

    It's kind of logical..

    Try:

    Code:
    Panel1.AddView(MapPanel, 00, Panel1.Width, Panel1.Height)
    Martin.
     
  7. adrianstanescu85

    adrianstanescu85 Active Member Licensed User

    Does anyone know what do I actually need to display for instance all hospitals on a 30km radius around a certain fixed location (current GPS position for instance)? If possible mark them with a marked, or even get their names...

    Thank you!
     
  8. Erel

    Erel Administrator Staff Member Licensed User

  9. GMan

    GMan Well-Known Member Licensed User

    Hi Erel,

    implemented the maps lib in my app and all works fine - great job ! :icon_clap:
     
  10. Laurent95

    Laurent95 Active Member Licensed User

    Emmmm, this words, just after the noise about the "Gay" marriage in France, hu ho...... (joke :sign0008: )
     
  11. sioconcept

    sioconcept Active Member Licensed User

    Is it possible to kill cleanly mapping ? (i think about MapFragment and GoogleMap)

    Thanks
     
  12. Erel

    Erel Administrator Staff Member Licensed User

    What do you mean with "kill cleanly"?
     
  13. AlteregoHR

    AlteregoHR Member Licensed User

    Thank you!
     
  14. sioconcept

    sioconcept Active Member Licensed User

    Excuse me, i declare Globals :

    Code:
    Dim mFragment       As MapFragment
    Dim GMap          As GoogleMap
    Dim GMapExtras      As GoogleMapsExtras
    Dim InfoWindow       As OnInfoWindowClickListener
    Dim MapPanel       As Panel 'Not in any Layout
    And i load GMap with :

    Code:
    MapPanel.Initialize("CartographieMenu")
    Activity.AddView(MapPanel, 00100%x100%y)
    If mFragment.IsGooglePlayServicesAvailable Then
       mFragment.Initialize(
    "Carto", MapPanel)
       MapPanel.BringToFront
    End if
    But, when i would like display another panel, i would like to kill mFragment and GMap because it causes a lot of freeze (i've near 10 000 markers).
     
  15. Erel

    Erel Administrator Staff Member Licensed User

    Try to clear the map with GoogleMap.Clear and then remove its panel with Panel.RemoveView.
     
  16. sioconcept

    sioconcept Active Member Licensed User

    Thanks Erel, is a good way.

    I've a last question about Tag; When i create a marker, i don't see "Tag" event. It's a little problem, because i can't put data (For exemple, the ID of the marker) to retreive it with Click event. For the moment, i wrote in snippet "#4520" to retreive it; so it's work of course, but it's not beautifull.
     
  17. Erel

    Erel Administrator Staff Member Licensed User

    Markers do not have a tag property. The "trick" in such cases it to use a Map. The Marker should be the key and the value should be any object you need to tie to this marker.
     
  18. AlteregoHR

    AlteregoHR Member Licensed User

    Can anyone please help me how to use BitmapDescriptor and
    BitmapDescriptorFactory to change marker icon? :sign0085:

    Thanks
     
  19. warwound

    warwound Expert Licensed User

    First make sure you have the GoogleMapsExtras library included in your project.

    Next you need to create an instance of a BitmapDescriptor and pass it to the MarkersOptions Icon method.
    You create an instance of a BitmapDescriptor by using an instance of BitmapDescriptorFactory.

    Finally you create your Marker using the GoogleMapsExtras AddMarker method instead of using the GoogleMaps AddMarker, AddMarker2 or AddMarker3 method.

    Code:
    Sub Process_Globals

    End Sub

    Sub Globals
        
    Dim MapFragment1 As MapFragment
        
    Dim GoogleMap1 As GoogleMap
       
    Dim GoogleMapsExtras1 As GoogleMapsExtras
        
    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
          
    '   use the new MarkerOptions method to create and add a Marker to the map
          
          
    Dim MarkerOptions1 As MarkerOptions
          MarkerOptions1.Initialize
          
          MarkerOptions1.Position2(
    52.756190.3980).Snippet("Home is where the heart is").Title("Home Sweet Home").Visible(True)
          
          
    Dim BitmapDescriptor1 As BitmapDescriptor
          
    Dim BitmapDescriptorFactory1 As BitmapDescriptorFactory
          
          
    '   both of these lines load the person.png image as a custom icon
          BitmapDescriptor1=BitmapDescriptorFactory1.FromAsset("person.png")
          
    '   this method could be used to load a Bitmap that is located somewhere other than the assets folder
          '   BitmapDescriptor1=BitmapDescriptorFactory1.FromBitmap(LoadBitmap(File.DirAssets, "person.png"))
          
          MarkerOptions1.Icon(BitmapDescriptor1)
          
          
    Dim Marker1 As Marker=GoogleMapsExtras1.AddMarker(GoogleMap1, MarkerOptions1)
          
            
    Dim CameraPosition1 As CameraPosition
            CameraPosition1.Initialize(
    52.756190.39806)
            GoogleMap1.AnimateCamera(CameraPosition1)
        
    End If
    End Sub
    Demo project attached, note you'll need to change the API key in the manifest to run the demo.

    Martin.
     

    Attached Files:

    hani bassam, Roger Daley and Powie like this.
  20. sioconcept

    sioconcept Active Member Licensed User

    Thanks for explain warwound :)
     
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