Page 1 of 1

GPS coordinates

Posted: Wed Dec 12, 2018 11:19 am
by Natter
Hi all !

Is it possible to get GPS coordinates by address ?

Re: GPS coordinates

Posted: Wed Dec 12, 2018 6:20 pm
by Antonio Linares
https://stackoverflow.com/questions/113 ... oordinates

Code: Select all

<script type="text/javascript">
var dir1 = "5th ave, new york";
var google_url = "http://maps.googleapis.com/maps/api/geocode/json?address=";
var sensor = "&sensor=false";
var resultado;

function myFunction(){ 

    $.getJSON(
        google_url+dir1+sensor,
        function(result){
            $( "body" ).append( "Latitude: " + JSON.stringify(result.results[0].geometry.bounds.northeast.lat) )
            $( "body" ).append( "Longitude: " + JSON.stringify(result.results[0].geometry.bounds.northeast.lng) )  
    });

}

Re: GPS coordinates

Posted: Thu Dec 13, 2018 7:34 am
by Natter
Thanks it is excellent! But how to make it on a FWH 18.06 ?!

Re: GPS coordinates

Posted: Thu Dec 13, 2018 7:59 am
by Antonio Linares

Code: Select all

#include "FiveWin.ch"

function Main()

   local cGoogleURL := "http://maps.googleapis.com/maps/api/geocode/json?address="
   local cAddress   := "5th ave, new york"
   local cSensor    := "&sensor=false"
   local cKey       := "&key=" + MY_API_KEY

   MsgInfo( WebPageContents( cGoogleURL + cAddress + cSensor + cKey ) )

return nil
To get your API Key:
https://developers.google.com/maps/docu ... sdk/signup

Re: GPS coordinates

Posted: Fri Oct 16, 2020 10:10 am
by Silvio.Falconi
run ok
but Now how obtainthe Lat e long from that message ?

Re: GPS coordinates

Posted: Fri Oct 16, 2020 1:13 pm
by AntoninoP
if you want you can try Nominatim with its Web API.
For example

Code: Select all

#include <fivewin.ch>
function Main()

   local cGoogleURL := "https://nominatim.openstreetmap.org/search?format=json&q="
   local cAddress   := "5th ave, new york"
   local aReturn, i, cTxt := ""
   aReturn := hb_jsonDecode( WebPageContents( cGoogleURL + cAddress) )
   if !empty(aReturn)
      for i:=1 to len(aReturn)
         cTxt += aReturn[i,"display_name"] + e"\r\n"
         cTxt += aReturn[i,"lat"]+" "+aReturn[i,"lon"] + e"\r\n" + e"\r\n"
      next
   else
      cTxt:="not found"
   endif
   MsgInfo(cTxt)
return nil

Re: GPS coordinates

Posted: Sat Oct 17, 2020 9:47 pm
by Otto
Hello Antonino,
when I try your sample I get only a number as aReturn.
CAn you help us, please.
Best regards,
Otto

Re: GPS coordinates

Posted: Sun Oct 18, 2020 12:46 am
by Cgallegoa
Otto:

This is correct:

Code: Select all

#include "FiveWin.ch"

function Main()

   local cGoogleURL := "https://nominatim.openstreetmap.org/search?format=json&q="
   local cAddress   := "5th ave, new york"
   local aReturn, i, cTxt := ""

  // aReturn := hb_jsonDecode( WebPageContents( cGoogleURL + cAddress) )   // *** Change this *** 
   aReturn := WebPageContents( cGoogleURL + cAddress)
   hb_jsondecode( aReturn, @aReturn )

   if !empty(aReturn)
      for i:=1 to len(aReturn)
         cTxt += aReturn[i,"display_name"] + e"\r\n"
         cTxt += aReturn[i,"lat"]+" "+aReturn[i,"lon"] + e"\r\n" + e"\r\n"
      next
   else
      cTxt:="not found"
   endif
   MsgInfo(cTxt)
return nil
 
Regards

Re: GPS coordinates

Posted: Sun Oct 18, 2020 6:55 am
by Otto
Hello Antonino, hello Carlos,
Thank you so much. All working.
Best regards,
Otto
Image

Re: GPS coordinates

Posted: Mon Oct 19, 2020 6:52 am
by AntoninoP
I am not sure, but the different syntax of hb_jsondecode is relative the Harbour and XHarbour implementations.

You can do the get on browser and use some tools like JSON formatter to see that there are a lot of other information.