Android Question Auto check current location to detect arrival at a particular site?

tsteward

Well-Known Member
Licensed User
Longtime User
In my app I create an sql record when I arrive at a job site. I use GPS and Geocoder to get the current address. - Works fine
Next time at this site I might forget to log that I'm there.

How would I auto detect arrival at an open job docket and departure from site.
 

tsteward

Well-Known Member
Licensed User
Longtime User
I would need to know how to get the gps coordinates of an address.

IE one of the techs jobs is at 45 High St Wondga Vic Australia. How might I get the gps coords
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
In my app I create an sql record when I arrive at a job site.
If you do that then your device will know the coordinates when you create your initial entry - you will be right there!
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
IE one of the techs jobs is at 45 High St Wondga Vic Australia. How might I get the gps coords

As @DonManfred suggested read up on Google Places API ... it really opens up what info you can get from a lat/lon , placeID parameter.

have a look at this as well ...Fused Location Provider GSM

Run the example ...that will give you the current location latitude & longitude for starters then build from there.


B4X:
'origin or destination parameter can be placeID (pefixed by place_id:) or Lat,Lon
'origin =place_id:ChIJ3S-JXmauEmsRUcIaWtf4MzE       
'destination=41.43206,-81.38992

Public Sub GetRoutePolyPointsString(origin As String, destination As String) As ResumableSub
   
    Dim polyPoints As String
    Dim j As HttpJob
    j.Initialize("", Me)
    j.Download2("https://maps.googleapis.com/maps/api/directions/json", Array As String("origin", origin, "destination", destination,"key",GoogleApiKey))
'...............................................


Sub GetTripDistanceData(source As String, destination As String) As ResumableSub
    Dim travelduration, traveldistance As Int
   
    Dim j As HttpJob
    j.Initialize("", Me)
    j.Download2("https://maps.googleapis.com/maps/api/directions/json", Array As String("origin", source,"destination", destination,"key", GoogleApiKey))
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Dim parser As JSONParser
        parser.Initialize(j.GetString)
        Dim mapRoot As Map = parser.NextObject
        If mapRoot.Get("status") = "OK" Then
            Dim lstRoutes As List = mapRoot.Get("routes")
            For Each mapRoutes As Map In lstRoutes
                Dim lstLegs As List = mapRoutes.Get("legs")
                For Each mapLegs As Map In lstLegs
                    'start_address  = mLegs.Get("start_address")
                    'end_address = mLegs.Get("end_address")
                    Dim lstSteps As List = mapLegs.Get("steps")
                    For Each mapSteps As Map In lstSteps
                        Dim mapDuration As Map = mapSteps.Get("duration")
                        travelduration = travelduration + mapDuration.Get("value")    'as Meters
                        Dim mapDistance As Map = mapSteps.Get("distance")
                        traveldistance = traveldistance + mapDistance.Get("value")      'as Seconds
                    Next
                Next
            Next
            Dim TripDistance As TripDistanceType
            TripDistance.TravelDistance = traveldistance
            TripDistance.TravelDuration = travelduration
            Return TripDistance
        Else
            Log("Error: " & mapRoot.Get("status"))
        End If
    Else
        Log("Error!")
    End If
    j.Release
End Sub
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Upvote 0

tsteward

Well-Known Member
Licensed User
Longtime User
I can get the address in currently at. I've convert GPS to address no problem.
What I haven't learnt yet is when a customer rings and gives me their address I need to get the GPS.

Anyway will read up on this thanks guys.
 
Upvote 0

emexes

Expert
Licensed User
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Type the address into PlacesAutoCompleteView

This will then return a place description and PlaceID. You can then use Google Geocoding API to get the Lat and Lon.
B4X:
Sub GetLatAndLonByPlaceID(PlaceID As String) As ResumableSub
   
    Dim Result() As Double = Array As Double(9999, 9999)
    Dim j As HttpJob
    j.Initialize("", Me)
    j.Download2("https://maps.googleapis.com/maps/api/geocode/json", Array As String("place_id", PlaceID, "key", GoogleApiKey))
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Dim parser As JSONParser
        parser.Initialize(j.GetString)
        Dim mapRoot As Map = parser.NextObject
        If mapRoot.Get("status") = "OK" Then
            Dim lstResults As List = mapRoot.Get("results")
            If lstResults.Size > 0 Then
                Dim mapFirst As Map = lstResults.Get(0)
                Dim mapGeometry As Map = mapFirst.Get("geometry")
                Dim mapLocation As Map = mapGeometry.Get("location")
                Result(0) = mapLocation.Get("lat")
                Result(1) = mapLocation.Get("lng")
            End If
        End If
    Else
        Log("Error!")
    End If
   
    j.Release
    Return Result
   
End Sub
 
Upvote 0

emexes

Expert
Licensed User
when a customer rings and gives me their address

Hey, is this only for use within Australia?

If so, check out:

https://data.gov.au/data/dataset/geocoded-national-address-file-g-naf

and, even better:

https://geoscape.com.au/data/g-naf-core/

which looks like it is the same data but already flattened to simplify using it.

I used this data 5 years ago when doing delivery driving: distilled out all addresses within 20km radius of centre of my delivery area = about 78,000 addresses = 4 MB plain text data = small enough to do keystroke-by-keystroke linear search that responded faster than anyone can type (after the first few characters, at least).

Jeez that was a beautiful app, did the routing (travelling salesperson problem), plus had a record of every address I ever delivered to, so that when I delivered there a second time I'd know precisely where the driveway was (road frontages of 100s of metres were common) and that I was looking for a red letterbox and wooden gate and to deliver to the right-hand door of the shed. Oh, and gate codes, or where the gate button was hidden.

Plus I'd photograph the delivery within the app and it would send it to the recipient's mobile or email with text eg "Delivery for Jane at front door".

But I never did get around to doing OCR on the delivery labels. Although tbh by the time you account for misreads, it was probably just as fast to type them in, eg by the time you'd typed in "1088" it would be down to one or two addresses, with previously-delivered addresses at the top of the list.
 
Upvote 0
Top