Share My Creation GPS Example

wm.chatman

Well-Known Member
Licensed User
Longtime User
Well I thought I would post this and maybe there would be some interest for these functions, as it would really make the GPS Example even greater.
If I had a chance to integrate such functions, I sure would not be asking for help on this, after guite some years not beiing online at this Domain.
These Enhancements would really kick off. Any helper are welcome and it would really put this litlle GPS Example to the Top.
It would be really great if we could set Waypoints/Tracks (individual) points that we can select.
I can select waypoint before I move away from vehicle waypoint 1, select the empire state buidng as waypoint 2,
waypoint 3, and so on. When I set these waypoints up in advance, they become a route.
The Track is where I actually walked. After I’ve walked all over who knows where, probably
deviating from my Route, I can find my track with the GPS unit and or save the track.
Or use the Trackback function to find my way back to the start. My Track will include some of my Waypoints, but
it will also include many other recorded points along the way. Using Trackback, I might see that I stopped
at the lake in Cetral Park at 2:57 PM, for example.

Btw Erel: This is a great and very clean site!
your tpl facelift is great, keep up the good work
 
Last edited:

wm.chatman

Well-Known Member
Licensed User
Longtime User
Last edited:

arjian

Member
Licensed User
Longtime User
hi,is that possible to use custom marker instead of the original one,for example by changing in the code below :
B4X:
HtmlCode = HtmlCode & "chart?chst=d_map_pin_letter&chld=A|00FF00|000000'});"
 

klaus

Expert
Licensed User
Longtime User
What marker do you want to change ?
Directly with this:
B4X:
HtmlCode = HtmlCode & "chart?chst=d_map_pin_letter&chld=A|00FF00|000000'});"
No
You need to change the end of this line:
B4X:
HtmlCode = HtmlCode & "; var marker" & n & " = new google.maps.Marker({    position: new google.maps.LatLng(" & Pos.Latitude & "," & Pos.Longitude & "),map: map, title: 'Test" & i & "',clickable: " & MarkersClickable & ", draggable: " & MarkersDragable & ", icon: 'http://chart.apis.google.com/"
 

arjian

Member
Licensed User
Longtime User
You need to change the end of this line:
B4X:
HtmlCode = HtmlCode & "; var marker" & n & " = new google.maps.Marker({    position: new google.maps.LatLng(" & Pos.Latitude & "," & Pos.Longitude & "),map: map, title: 'Test" & i & "',clickable: " & MarkersClickable & ", draggable: " & MarkersDragable & ", icon: 'http://chart.apis.google.com/"

thanks,
i want to use a custom graphic file,something like this:

B4X:
HtmlCode = HtmlCode & "; var markerc = new google.maps.Marker({    position: new google.maps.LatLng(" & CenterLat & "," & CenterLng & "),map: map, title: '',clickable: false,icon: '" & File.Combine(File.DirAssets,"marker.png") & "' })"
but it doesn't work and i don't know how to fix it
 

klaus

Expert
Licensed User
Longtime User
What marker do you want to change ?
The center marker or the path markers ?
If it's the center marker you must change it in line
HtmlCode = HtmlCode & "; var markerc = new google.maps.Marker({ position: new google.maps.LatLng(" & CenterLat & "," & CenterLng & "),map: map, title: '',clickable: false,icon: 'http://www.google.com/mapfiles/arrow.png' })"

You cannot use File.Combine(File.DirAssets,"marker.png")
you must use " 'file:///android_asset/marker.png' " instead

For the center marker try this:
HtmlCode = HtmlCode & "; var markerc = new google.maps.Marker({ position: new google.maps.LatLng(" & CenterLat & "," & CenterLng & "),map: map, title: '',clickable: false,icon: 'file:///android_asset/marker.png' })"
 

arjian

Member
Licensed User
Longtime User
hi
sorry to bother you again,i read a lot(e.g https://google-maps-utility-library...tags/markerwithlabel/1.0.1/docs/examples.html) but i couldn't find answer for following questions if you help me i would appreciate that
  • add a text to custom marker by changing code,something like this (of curse this code doesn't work):
B4X:
HtmlCode = HtmlCode & "; var markerc = new google.maps.Marker({    position: new google.maps.LatLng(" & CenterLat & "," & CenterLng & "),map: map, title: '',clickable: false,icon: 'file:///android_asset/marker.png&chld=A|00FF00|000000' })"
  • set the center of custom graphic marker to the Latitude and Longitude instead of bottom of marker
the second one is important to me and i know the first one is too difficult
thank you
 
Last edited:

klaus

Expert
Licensed User
Longtime User
1) Setting a value for title seems not working.
I made some trials but it doesn't work.
I looked at the documentation and found that title is shown on a PC only when the mouse hovers over the marker.
I'm afraid that this hovering function doesn't exist in Android and title is not displayed.


2) You can use this code, you need to adapt the values for size and achor.
B4X:
HtmlCode = HtmlCode & "var myIcon = { "
HtmlCode = HtmlCode & "url: 'file:///android_asset/marker.png', "
HtmlCode = HtmlCode & "size: new google.maps.Size(50, 50),"
HtmlCode = HtmlCode & "origin: new google.maps.Point(0,0), "
HtmlCode = HtmlCode & "anchor: new google.maps.Point(25,25), "
HtmlCode = HtmlCode & "};"
HtmlCode = HtmlCode & "var markerc = new google.maps.Marker({    "
HtmlCode = HtmlCode & "position: new google.maps.LatLng(" & CenterLat & "," & CenterLong & "),"
HtmlCode = HtmlCode & "map: map, title: '',clickable: false,"
HtmlCode = HtmlCode & "icon: myIcon "
HtmlCode = HtmlCode & "});"
 

Frank Tolsma

New Member
Licensed User
Longtime User
I am new to Basic4Android, but I like what I see so far...
For people who are trying this (nice) example project:

The 4 libraries listed in the first post are not the ones that are actually needed (anymore?).

The project also needs the ScrollView2D library. I could not find that one in the libraries list: http://www.b4x.com/android/wiki/index.php/Libraries, but I did find it here: http://www.b4x.com/android/forum/threads/lib-scrollview2d.19268/

It does not seem to need the Dialogs library, or at least: it compiles without it...
 

klaus

Expert
Licensed User
Longtime User
This code was written quite some time ago.
In between we have access to the GPS NMEA event where we can get the altitude above sea level in the GGA sentence.
I don't understand why the Google gurus don't return the altitude above sea level in the GPS_LocationChanged event.
Look at the first post, the program has been updated.
 

acortez

New Member
Hi Klaus. This is a very good GPS example I must say and I applaud you on this. Thank you.
But I'm having an error in this line of code on my Samsung Rush. I'd appreciate it very much if you can you shed a light on this.

Sub GPS1_NMEA (TimeStamp As Long, Sentence As String)
If Sentence.SubString2(0, 6) = "$GPGGA" Then
Dim vals() As String
vals = Regex.Split(",", Sentence)
GPSAltitudeSeaLevel = vals(9) <----------- throws an error
End If
End Sub

Error Description:
An error has occured in sub: java.lang.NumberFormatException:Invalid double:""

I don't know if this is phone related as I have not tested it yet with any other phone.
 

Roger Daley

Well-Known Member
Licensed User
Longtime User
Klaus

Thanks for posting this example/code. I had a vague idea for an APP to solve an old work problem [mental excercise] that would mean I had to come to grips with GPS, Google maps etc. and couldn't figure out where to start. Reverse engineering your example [stealing] is going to give me that knowledge and a whole lot more experience in B4A. Probably my 2015 project.
Great work as usual.

Regards Roger
 

Roger Daley

Well-Known Member
Licensed User
Longtime User
Klaus

A small bug, if there is no GPS signal and you press the GPS button you get an error.
The error comes from here:

B4X:
Sub GPS1_NMEA (TimeStamp As Long, Sentence As String)
    If Sentence.SubString2(0, 6) = "$GPGGA" Then
        Dim vals() As String
        vals = Regex.Split(",", Sentence)
                                                            'GPSAltitudeSeaLevel = 0
                                                            'If vals(9) <> "" Then
        GPSAltitudeSeaLevel = vals(9)    '<<<< Error Line
                                                            'End If
    End If
End Sub

I can eliminate the error with code shown as comments but as I am still trying figure out what is what you probably have a much better solution.

Regards Roger
 

klaus

Expert
Licensed User
Longtime User
Thank you for reporting this:
Try this code.
B4X:
Sub GPS1_NMEA (TimeStamp As Long, Sentence As String)
    If GPS1.GPSEnabled = True Then
        If Sentence.SubString2(0, 6) = "$GPGGA" Then
            Dim vals() As String
            vals = Regex.Split(",", Sentence)
            GPSAltitudeSeaLevel = vals(9)
        End If
    End If
End Sub
EDIT:
The code above doesn't work.
Use the code below:
B4X:
Sub GPS1_NMEA (TimeStamp As Long, Sentence As String)
    If Sentence.SubString2(0, 6) = "$GPGGA" Then
        Dim vals() As String
        vals = Regex.Split(",", Sentence)
        If IsNumber(vals(9)) Then
            GPSAltitudeSeaLevel = vals(9)
        End If
    End If
End Sub
 
Last edited:
Cookies are required to use this site. You must accept them to continue using the site. Learn more…