Android Question Adress to Coordonates GPS location

ciginfo

Well-Known Member
Licensed User
Longtime User
Hello,
With "Geolocation" I know to get an adress from longitude and latitude, but what is code to get longitude and latitude from an adress.
Thank you
 

Star-Dust

Expert
Licensed User
Longtime User
In the forum you can find everything. Using the search function will be very useful to you

 
Upvote 0

emexes

Expert
Licensed User
I have used this, maybe France has something similar. Our state government has similar free public datasets available, eg every road speed zone in the state.
This looks promising:

The first French collaborative National Address Database is now online, and freely accessible.
The BAN associates each address listed on the French territory (25 million addresses) with its geographic coordinates.

This looks like the file:

https://adresse.data.gouv.fr/data/ban/adresses/latest/csv/adresses-france.csv.gz

Seems to be semicolon-separated rather than comma-separated but if that's our biggest problem, then I think we're on the home stretch:
B4X:
id;id_fantoir;numero;rep;nom_voie;code_postal;code_insee;nom_commune;code_insee_ancienne_commune;nom_ancienne_commune;x;y;lon;lat;alias;nom_ld;libelle_acheminement;nom_afnor;source_position;source_nom_voie
17002_yssy3h_00001;;1;;Route de l’Abbaye;17500;17002;Agudelle;;;429137.84;6481692.86;-0.462021;45.381192;;;AGUDELLE;ROUTE DE L ABBAYE;inconnue;inconnue
17002_yssy3h_00002;;2;;Route de l’Abbaye;17500;17002;Agudelle;;;429137.84;6481692.86;-0.462021;45.381192;;;AGUDELLE;ROUTE DE L ABBAYE;inconnue;inconnue
17002_yssy3h_00003;;3;;Route de l’Abbaye;17500;17002;Agudelle;;;429137.84;6481692.86;-0.462021;45.381192;;;AGUDELLE;ROUTE DE L ABBAYE;inconnue;inconnue
17002_yssy3h_00004;;4;;Route de l’Abbaye;17500;17002;Agudelle;;;429137.84;6481692.86;-0.462021;45.381192;;;AGUDELLE;ROUTE DE L ABBAYE;inconnue;inconnue
17002_yssy3h_00005;;5;;Route de l’Abbaye;17500;17002;Agudelle;;;429137.84;6481692.86;-0.462021;45.381192;;;AGUDELLE;ROUTE DE L ABBAYE;inconnue;inconnue
17002_yssy3h_00001_a;;1;a;Route de l’Abbaye;17500;17002;Agudelle;;;428997.37;6481342.86;-0.463618;45.377988;;;AGUDELLE;ROUTE DE L ABBAYE;arcep;inconnue
17002_yssy3h_00001_b;;1;b;Route de l’Abbaye;17500;17002;Agudelle;;;429115.9;6481667.58;-0.462287;45.380956;;;AGUDELLE;ROUTE DE L ABBAYE;arcep;inconnue
17002_auqti8_00001;;1;;Le Groizard Chemin de l’Étang;17500;17002;Agudelle;;;428191.67;6482852.96;-0.474751;45.391254;;;AGUDELLE;LE GROIZARD CHEMIN DE L ETANG;inconnue;inconnue
17002_auqti8_00003;;3;;Le Groizard Chemin de l’Étang;17500;17002;Agudelle;;;428191.67;6482852.96;-0.474751;45.391254;;;AGUDELLE;LE GROIZARD CHEMIN DE L ETANG;inconnue;inconnue
17002_auqti8_00005;;5;;Le Groizard Chemin de l’Étang;17500;17002;Agudelle;;;428191.67;6482852.96;-0.474751;45.391254;;;AGUDELLE;LE GROIZARD CHEMIN DE L ETANG;inconnue;inconnue
17002_auqti8_00007;;7;;Le Groizard Chemin de l’Étang;17500;17002;Agudelle;;;428191.67;6482852.96;-0.474751;45.391254;;;AGUDELLE;LE GROIZARD CHEMIN DE L ETANG;inconnue;inconnue
17002_vxge1k_00001;;1;;Chez Limousin;17500;17002;Agudelle;;;428560.47;6482330.39;-0.469749;45.386699;;;AGUDELLE;CHEZ LIMOUSIN;inconnue;inconnue
 
Last edited:
Upvote 0

ciginfo

Well-Known Member
Licensed User
Longtime User
In the forum you can find everything. Using the search function will be very useful to you

I have found nothing with Geolocation library.
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Upvote 0

ciginfo

Well-Known Member
Licensed User
Longtime User
the code that I have indicated allows you to have the same result without library. If you have a key for Google Maps using the internet api.
Yes, thank you, but why this code returns 9999 & 9999 and not Latitude and longitute of Israel Yodfat ? Where is the problem ?
I put in the manifest as indicated anf API_KEY is correct.
B4X:
Sub Globals
    Dim API_KEY As String
    API_KEY = "AIzaSyDo*************SIrU*******u5oPI"
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Layout")
    Wait For(PlaceToLatLon("Israel Yodfat")) Complete (ll() As Double)
    If ll(0) <> 9999 Then
        Log("Location: " & ll(0) & ", " & ll(1))
    Else
        Log("Failed to geocode.")
    End If
    
End Sub

Sub PlaceToLatLon(Place As String) As ResumableSub
    Dim res() 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("key", API_KEY, "address", Place))
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Dim jp As JSONParser
        jp.Initialize(j.GetString)
        Dim m As Map = jp.NextObject
        If m.Get("status") = "OK" Then
            Dim results As List = m.Get("results")
            If results.Size > 0 Then
                Dim first As Map = results.Get(0)
                Dim geometry As Map = first.Get("geometry")
                Dim location As Map = geometry.Get("location")
                res(0) = location.Get("lat")
                res(1) = location.Get("lng")
                Log(res(0))
                Log(res(1))
            End If
        End If
    Else
        Log("Error!")
    End If
    j.Release
    Return res
End Sub
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
these values indicate that it did not find the location.
Try another address, possibly a known one and see if it still returns you 9999
 
Upvote 0

ciginfo

Well-Known Member
Licensed User
Longtime User
Try Log(j.GetString) and see what is the value.
Thank you,
Log(j.GetString) -> "error_message" : "This API project is not authorized to use this API.",
I use this API_KEY with an other application and it runs fine. Have I tu use a different API_KEY for every application?
Thank you
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
The api key is probably bound to a specific package.
You need to check it in the google gloud console.
 
Upvote 0

ciginfo

Well-Known Member
Licensed User
Longtime User
I have created a new Api Key but I get the same error message in Log(j.GetString) : "This API project is not authorized to use this API.",
I go to : https://console.cloud.google.com/pr...rview=project&folder=true&organizationId=true
Then "New project" -> Create
I obtain an Api Key "AIzaSyAosZSkD*************6Wn30pais"
I write in Manifest :
B4X:
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
AddApplicationText(
<meta-data
  android:name="com.google.android.geo.API_KEY"
  android:value="AIzaSyAosZSkD*************6Wn30pais"/>
)
AddApplicationText(
<uses-library
      android:name="org.apache.http.legacy"
      android:required="false" />
)
In Process_Global : I write :
Dim API_KEY As String
API_KEY = "AIzaSyAosZSkD*************6Wn30pais"

WHERE IS MY ERROR ?
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
Do you select the Key restrictions to None?
 
Upvote 0

ciginfo

Well-Known Member
Licensed User
Longtime User
Do you select the Key restrictions to None?
Yes. Here My Api KeyApi_Key.jpg
 
Upvote 0

Similar Threads

Top