FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour GPS coordinates
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
GPS coordinates
Posted: Wed Dec 12, 2018 11:19 AM

Hi all !

Is it possible to get GPS coordinates by address ?

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: GPS coordinates
Posted: Wed Dec 12, 2018 06:20 PM
https://stackoverflow.com/questions/11318347/geoencode-address-to-gps-coordinates

Code (fw): Select all Collapse
<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) )  
    });

}
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 1392
Joined: Mon May 14, 2007 09:49 AM
Re: GPS coordinates
Posted: Thu Dec 13, 2018 07:34 AM

Thanks it is excellent! But how to make it on a FWH 18.06 ?!

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: GPS coordinates
Posted: Thu Dec 13, 2018 07:59 AM
Code (fw): Select all Collapse
#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/documentation/android-sdk/signup
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 7317
Joined: Thu Oct 18, 2012 07:17 PM
Re: GPS coordinates
Posted: Fri Oct 16, 2020 10:10 AM

run ok
but Now how obtainthe Lat e long from that message ?

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Posts: 375
Joined: Tue Feb 10, 2015 09:48 AM
Re: GPS coordinates
Posted: Fri Oct 16, 2020 01:13 PM
if you want you can try Nominatim with its Web API.
For example
Code (fw): Select all Collapse
#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
Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: GPS coordinates
Posted: Sat Oct 17, 2020 09:47 PM

Hello Antonino,
when I try your sample I get only a number as aReturn.
CAn you help us, please.
Best regards,
Otto

Posts: 514
Joined: Sun Oct 16, 2005 03:32 AM
Re: GPS coordinates
Posted: Sun Oct 18, 2020 12:46 AM
Otto:

This is correct:
Code (fw): Select all Collapse
#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

Saludos,



Carlos Gallego



*** FWH-25.12, xHarbour 1.3.1 Build 20241008, Borland C++7.70, PellesC, ADS 11.1***

Posts: 6983
Joined: Fri Oct 07, 2005 07:07 PM
Re: GPS coordinates
Posted: Sun Oct 18, 2020 06:55 AM
Hello Antonino, hello Carlos,
Thank you so much. All working.
Best regards,
Otto
Posts: 375
Joined: Tue Feb 10, 2015 09:48 AM
Re: GPS coordinates
Posted: Mon Oct 19, 2020 06:52 AM
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.

Continue the discussion