Android Question Google Map Polyline

Discussion in 'Android Questions' started by BarryW, Apr 16, 2015.

Similar threads

B4A Code Snippet [B4X] Google Geocoding REST API
B4A Example MapsDecodePolyline
B4A Question polyline from kml to txt
B4A Question Invalid marker position on googlemap
B4A Tutorial GPS tutorial
  1. BarryW

    BarryW Active Member Licensed User

    Hi masters i have a problem in doing polyline in my google map v2

    Here is my code for sending request to google map
    Code:
    Dim job As HttpJob
            job.Initialize(
    "RoadPath", Me)
            job.Download(
    "http://maps.googleapis.com/maps/api/directions/json?origin=14.5888588,120.9763476&destination=" & _
                ResLocation.Latitude & 
    "," & ResLocation.Longitude & "&sensor=True")
    My code on JobDone
    Code:
    Sub JobDone (Job As HttpJob)
        
    ProgressDialogHide
        
    Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
        
    If Job.Success = True Then
            
    Select Job.JobName
                
    Case "RoadPath"
                    JsonTree(Job.GetString)
            
    End Select
        
    Else
            
    Log("Error: " & Job.ErrorMessage)
            
    ToastMessageShow("Error: " & Job.ErrorMessage, True)
        
    End If
        Job.Release
    End Sub
    And here is my code for getting the latitude and longhitude
    I used JSON Tree
    Code:
    Sub JsonTree(StrFile As String)
        
    Dim PL As Polyline
        PL = gmap.AddPolyline
        PL.Width = 
    4
        PL.Color = 
    Colors.Blue
        PL.Visible = 
    True
        PL.Geodesic = 
    True
       
        
    Dim CoorList As List : CoorList.Initialize
       
        
    Dim parser As JSONParser
        parser.Initialize(StrFile)
        
    Dim root As Map = parser.NextObject
        
    Dim status As String = root.Get("status")
        
    Dim routes As List = root.Get("routes")
        
    For Each colroutes As Map In routes
            
    Dim summary As String = colroutes.Get("summary")
            
    Dim bounds As Map = colroutes.Get("bounds")
            
    Dim southwest As Map = bounds.Get("southwest")
            
    Dim lng As Double = southwest.Get("lng")
            
    Dim lat As Double = southwest.Get("lat")
            
    Dim northeast As Map = bounds.Get("northeast")
            
    Dim lng As Double = northeast.Get("lng")
            
    Dim lat As Double = northeast.Get("lat")
            
    Dim copyrights As String = colroutes.Get("copyrights")
            
    Dim waypoint_order As List = colroutes.Get("waypoint_order")
            
    Dim legs As List = colroutes.Get("legs")
            
    For Each collegs As Map In legs
                
    Dim duration As Map = collegs.Get("duration")
                
    Dim text As String = duration.Get("text")
                
    Dim value As Int = duration.Get("value")
                
    Dim distance As Map = collegs.Get("distance")
                
    Dim text As String = distance.Get("text")
                
    Dim value As Int = distance.Get("value")
                
    Dim end_location As Map = collegs.Get("end_location")
                
    Dim lng As Double = end_location.Get("lng")
                
    Dim lat As Double = end_location.Get("lat")
                
    Dim start_address As String = collegs.Get("start_address")
                
    Dim end_address As String = collegs.Get("end_address")
                
    Dim start_location As Map = collegs.Get("start_location")
                
    Dim lng As Double = start_location.Get("lng")
                
    Dim lat As Double = start_location.Get("lat")
                
    Dim via_waypoint As List = collegs.Get("via_waypoint")
                
    Dim steps As List = collegs.Get("steps")
                
    For Each colsteps As Map In steps
                    
    Dim html_instructions As String = colsteps.Get("html_instructions")
                    
    Dim duration As Map = colsteps.Get("duration")
                    
    Dim text As String = duration.Get("text")
                    
    Dim value As Int = duration.Get("value")
                    
    Dim distance As Map = colsteps.Get("distance")
                    
    Dim text As String = distance.Get("text")
                    
    Dim value As Int = distance.Get("value")
                   
                    
    Dim start_location As Map = colsteps.Get("start_location")
                    
    Dim lng As Double = start_location.Get("lng")
                    
    Dim lat As Double = start_location.Get("lat")
                    
    Dim Temp As LatLng : Temp.Initialize(lat, lng)
                    CoorList.Add(Temp)
                    
    Log("Start: " & lat & ", " & lng)
                   
                    
    Dim end_location As Map = colsteps.Get("end_location")
                    
    Dim lng As Double = end_location.Get("lng")
                    
    Dim lat As Double = end_location.Get("lat")
                    
    Dim Temp2 As LatLng : Temp2.Initialize(lat, lng)
                    CoorList.Add(Temp2)
                    
    Log("End: " & lat & ", " & lng)
                   
                    
    Dim Polyline As Map = colsteps.Get("polyline")
                    
    Dim points As String = Polyline.Get("points")
                   
                    
    Dim travel_mode As String = colsteps.Get("travel_mode")
                    
    Log("Trave Mode: " & travel_mode)
                
    Next
            
    Next
            
    Dim warnings As List = colroutes.Get("warnings")
            
    Dim overview_polyline As Map = colroutes.Get("overview_polyline")
            
    Dim points As String = overview_polyline.Get("points")
        
    Next

        PL.Points = CoorList
    End Sub
    Note: ResLocation.Latitude and ResLocation.Longhitude is coming for my gps result

    And here is the result of my polyline. My Problem is my polyline is not snapping on some road path

    Tnx.. I hope some could help me...
     
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