Android Question Google maps marker

Discussion in 'Android Questions' started by Almora, May 19, 2017.

  1. Almora

    Almora Active Member Licensed User

    How can i do just a marker.
    I'm using FusedLocationProvider


    Code:
    Public m1 As Marker
            m1=gmap.AddMarker2(Location1.Latitude,Location1.Longitude,
    "Lon: " &Location1.Longitude, 200 )
            m1.Snippet=
    "Lat: " & Location1.Latitude
            m1.InfoWindowShown=
    True
           
            
    Dim cp As CameraPosition
            cp.Initialize(Location1.Latitude, Location1.Longitude, 
    14)
            gmap.AnimateCamera(cp)
     

    Attached Files:

  2. DonManfred

    DonManfred Expert Licensed User

    What is the exact question? I do not understand

    Edit: Looking at the picture it looks like you are adding a lot of markers....
     
  3. Almora

    Almora Active Member Licensed User

    When I move, you only see a marker.
     
  4. DonManfred

    DonManfred Expert Licensed User

    Why are you adding more than one Marker then?

    1. Get the map
    2. Add a Marker and remember it´s object (global var for ex)
    Code:
    Dim mymarker As Marker ' Global var
        mymarker = gmap.AddMarker(-8.841878,-75.750383""' get the markerobject
    inside your new location event you update the marker with
    Code:
    mymarker.Position = newposition
     
    Almora likes this.
  5. Almora

    Almora Active Member Licensed User

    Code:
    Dim LaLo As LatLng
    LaLo.Initialize(location1.Latitude,location1.Longitude)
    m1.Position = LaLo
    I used this code. But again the same. Many markers appear.
     

    Attached Files:

  6. DonManfred

    DonManfred Expert Licensed User

    Upload a small project which shows the problem. Based on the code snippets you posted i cannot help!
     
  7. Almora

    Almora Active Member Licensed User

    added..
     
  8. DonManfred

    DonManfred Expert Licensed User

    You are STILL adding multiple markers.... Add the MARKER the FIRST TIME. After that just use the markerobject.
    Code:
    Sub FusedLocationProvider1_LocationChanged(Location1 As Location)
        
    Log("FusedLocationProvider1_LocationChanged")
        LastLocation=Location1

        
    If gmap.IsInitialized = False Then
            
    ToastMessageShow("Error initializing map."True)
        
    Else  
                              
            m1=gmap.AddMarker2(Location1.Latitude,Location1.Longitude,
    "Lon: " &Location1.Longitude, 200 )
    Add the marker here once....
    Code:
    Sub MapFragment1_Ready
       
        gmap = MapFragment1.GetMap
        m1=gmap.AddMarker2(
    15,15,"Lon: " &15200 )

    End Sub
    Then in you location changed you just need to update the known marker.
     
  9. Almora

    Almora Active Member Licensed User

    I could not..
    :(
     
  10. DonManfred

    DonManfred Expert Licensed User

    I´ve revisited your project.
    A few remarks:
    - You don´t need Runtimepermissions if you set targetsdk to 19 like you did.
    - As i wrote above; you need to create one marker and reuse the markerobject to change it´s position.

    Code:
    Sub MapFragment1_Ready
        
    Log($"MapFragment1_Ready()"$)
        gmap = MapFragment1.GetMap
        m1=gmap.AddMarker2(
    15,15,"DummyLocation"200 )
        
    Log($"Marker set at dummy-position..."$)
    End Sub
    and then - in your locationchanged even - you set the new Location to the marker

    Code:
    Sub FusedLocationProvider1_LocationChanged(Location1 As Location)
        
    Log($"FusedLocationProvider1_LocationChanged(GMap initialized = ${gmap.IsInitialized})"$)
        LastLocation=Location1
        
    If gmap.IsInitialized = False Then
            
    ToastMessageShow("Error initializing map."True)
        
    Else
            
    Log($"Changing marker-position to Lat: ${Location1.Latitude}, Lon: ${Location1.Longitude}"$)
            m1.Title = 
    "Location"
            m1.Snippet=
    $"Lat: ${Location1.Latitude} Lon: ${Location1.Longitude}"$
            m1.InfoWindowShown=
    True
           
            
    Dim LaLo As LatLng
            LaLo.Initialize(Location1.Latitude,Location1.Longitude)
            m1.Position = LaLo  
    'new Position
           
            
    Dim cp As CameraPosition
            cp.Initialize(Location1.Latitude, Location1.Longitude, 
    14)
            gmap.AnimateCamera(cp)
           
            gmap.MyLocationEnabled=
    True
        
    End If
    End Sub
     
    Last edited: May 19, 2017
    BillMeyer and Almora like this.
  11. Almora

    Almora Active Member Licensed User

    very good.
    How can I donate outside of PayPal.
     
  12. DonManfred

    DonManfred Expert Licensed User

    Which ways are possible?
    Honestly i do not have any other Account somewhere. Beside my Bankaccount in Germany
     
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