GPS coordinates

Post Reply
Natter
Posts: 524
Joined: Mon May 14, 2007 9:49 am

GPS coordinates

Post by Natter »

Hi all !

Is it possible to get GPS coordinates by address ?
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: GPS coordinates

Post 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) )  
    });

}
regards, saludos

Antonio Linares
www.fivetechsoft.com
Natter
Posts: 524
Joined: Mon May 14, 2007 9:49 am

Re: GPS coordinates

Post by Natter »

Thanks it is excellent! But how to make it on a FWH 18.06 ?!
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: GPS coordinates

Post 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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Silvio.Falconi
Posts: 4956
Joined: Thu Oct 18, 2012 7:17 pm

Re: GPS coordinates

Post by Silvio.Falconi »

run ok
but Now how obtainthe Lat e long from that message ?
I use : FiveWin for Harbour August 2020 (Revision) - Harbour 3.2.0dev (r1712141320) - Bcc7.30 - xMate ver. 1.15.3 - PellesC
AntoninoP
Posts: 347
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy
Contact:

Re: GPS coordinates

Post 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
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Re: GPS coordinates

Post by Otto »

Hello Antonino,
when I try your sample I get only a number as aReturn.
CAn you help us, please.
Best regards,
Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org

********************************************************************
Cgallegoa
Posts: 335
Joined: Sun Oct 16, 2005 3:32 am
Location: Quito - Ecuador
Contact:

Re: GPS coordinates

Post 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
Saludos,

Carlos Gallego

*** FWH-20.07, xHarbour 1.2.3 Build 20190603, Borland C++7.30, PellesC ***
User avatar
Otto
Posts: 4470
Joined: Fri Oct 07, 2005 7:07 pm
Contact:

Re: GPS coordinates

Post by Otto »

Hello Antonino, hello Carlos,
Thank you so much. All working.
Best regards,
Otto
Image
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org

********************************************************************
AntoninoP
Posts: 347
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy
Contact:

Re: GPS coordinates

Post 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.
Post Reply