iOS Question Problems Googlemaps + api

Carlos marin

Active Member
Licensed User
Longtime User
Hi all experts,
I'm having some problems with googlemaps
1. use gmap_CameraChange to put a marker in the middle of the map and so the user moves it to where you want (see photo 1), the problem is when I put a map on another page the pointer moves down and I do not know why, I use the same code (see photo2)
B4X:
Sub gmap_CameraChange (Position As CameraPosition)
    MapScale1.Update(Position.Zoom, Position.Target.Latitude)
    Dim ll As LatLng
    ll.Initialize(Position.Target.Latitude,Position.Target.Longitude)
    amarker.Position=ll
End Sub

2. I use GetDirections of this thread https://www.b4x.com/android/forum/threads/b4x-google-geocoding-rest-api.83870/#content, the only thing I need is to work with JavaObject in b4i but I can not find a library or how to replace the last sub
B4X:
Sub drawDirections
    Dim jo As JavaObject
    Dim Points As List
    Points.Initialize
    jo.InitializeContext
    Points = jo.RunMethod("decodePoly", Array(polyPoints))
    If Points.Size > 0 Then
        pline = gmap.AddPolyline
        pline.Points = Points
        pline.Color = Colors.Black
    End If
End Sub
I thank you very much for any help and for your time
 

Attachments

  • photo 1.jpeg
    photo 1.jpeg
    118.4 KB · Views: 245
  • photo 2.jpeg
    photo 2.jpeg
    117.7 KB · Views: 238

Carlos marin

Active Member
Licensed User
Longtime User
Hi experts.
doing tests I found that if I open another page and then I open the map page, it does not load the map correctly in the panel. I really do not know what is altering this result. (see photo 3), what will happen? :eek::(:(
 

Attachments

  • photo 3.jpeg
    photo 3.jpeg
    57.4 KB · Views: 216
Upvote 0

Carlos marin

Active Member
Licensed User
Longtime User
Hi Erel,
I have 3 pages where I use the maps and I call the sub at the show event of each one

B4X:
Public Sub Show
    If Pg.IsInitialized = False Then
        Pg.Initialize("pg")
        Pg.RootPanel.LoadLayout("domiride")
        Pg.RootPanel.Color = Colors.White
        LocManager.Initialize("LocManager")
        AddMap
    End If
    'Pg.HideBackButton=True
    Main.NavControl.ShowPage(Pg)
End Sub

sub event
B4X:
Private Sub AddMap
    gmap.Initialize("gmap", ApiKey)
    Pnlmapa.AddView(gmap, 0, 0, 100%X, 100%y)
    'gmap.MapType = gmap.MAP_TYPE_TERRAIN
    gmap.GetUiSettings.CompassEnabled = True
    gmap.GetUiSettings.MyLocationButtonEnabled = True
    gmap.MyLocationEnabled = True
    Dim c As CameraPosition
    c.Initialize(6.249185030951583,-75.56865990535721, 14)
    gmap.AnimateCamera(c)
    amarker = gmap.AddMarker3(6.249185030951583,-75.56865990535721,"",LoadBitmapResize(File.DirAssets,"iconomaps.png",45,45,False))
End Sub
refers to this sub
B4X:
Private Sub Page1_Resize(Width As Int, Height As Int)
   'code......
End Sub
I am working on the based of this example https://www.b4x.com/android/forum/threads/multiple-pages-example.48170/#content that's why I did not see how to use the resize, all the pages load well except the map is redimensioned incorrectly. I would really appreciate if you could indicate a thread to look at some examples
 
Upvote 0

Carlos marin

Active Member
Licensed User
Longtime User
Maps it works very well thanks. going to point two I'm using NativeObject and it recognizes all the commands but how do I initialize it?

B4X:
Sub drawDirections
    Dim jo As NativeObject
    Dim Points As List
    Points.Initialize
  'how??  jo.Initialize("??????")
    Points = jo.RunMethod("decodePoly", Array(polyPoints))
    If Points.Size > 0 Then
        pline = gmap.AddPolyline
        pline.Points = Points
        pline.Color = Colors.Black
    End If
End Sub
 
Upvote 0

Carlos marin

Active Member
Licensed User
Longtime User
ooh god, I need to convert this code right?

B4X:
#if JAVA
/**
    * Method to decode polyline points
    * Courtesy : jeffreysambells.com/2010/05/27/decoding-polylines-from-google-maps-direction-api-with-java
    * */
import java.util.ArrayList;
import java.util.List;
import com.google.android.gms.maps.model.LatLng;
  
    public List<LatLng> decodePoly(String encoded){

        List<LatLng> poly = new ArrayList<LatLng>();
        int index = 0, len = encoded.length();
        int lat = 0, lng = 0;

        while (index < len) {
            int b, shift = 0, result = 0;
            do {
                b = encoded.charAt(index++) - 63;
                result |= (b & 0x1f) << shift;
                shift += 5;
            } while (b >= 0x20);
            int dlat = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
            lat += dlat;

            shift = 0;
            result = 0;
            do {
                b = encoded.charAt(index++) - 63;
                result |= (b & 0x1f) << shift;
                shift += 5;
            } while (b >= 0x20);
            int dlng = ((result & 1) != 0 ? ~(result >> 1) : (result >> 1));
            lng += dlng;
            LatLng p = new LatLng((((double) lat / 1E5)), (((double) lng / 1E5)));
            poly.add(p);
        }
        return poly;
    }
#End If

but I do not have the xcode or a mac, how do I do it? :confused::eek:
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Translate it to B4i, it is not a complex code
 
Upvote 0

Carlos marin

Active Member
Licensed User
Longtime User
hello Star-Dust time without seeing it, just recently acquired the b4i the truth is very little you could give me some guidelines or some help, the funny thing is that nobody has used the api directions of google to move routes (in b4i)
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Frankly I do not know the Google Api enough to give you advice.

But the code I saw is just a decoding and looking at it quickly does not seem complex.

Unfortunately, I'm out of the office now and I can not help you. But think about translating line by line and I think something will get you.
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
Search for MapsDecodePolyLine (there is a B4i adapted version by @marcick HERE). You'll need to tune it a bit since the example in the post places the result in a Global var instead of returning it.
I added it to a 'tuned' work version of GoogleMapsExtra since, at least when I needed it, it wasn't included.
 
Upvote 0
Top