GPS coordinates

GPS coordinates

Postby Natter » Wed Dec 12, 2018 11:19 am

Hi all !

Is it possible to get GPS coordinates by address ?
Natter
 
Posts: 1215
Joined: Mon May 14, 2007 9:49 am

Re: GPS coordinates

Postby Antonio Linares » Wed Dec 12, 2018 6:20 pm

https://stackoverflow.com/questions/11318347/geoencode-address-to-gps-coordinates

Code: Select all  Expand view
<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
User avatar
Antonio Linares
Site Admin
 
Posts: 42082
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: GPS coordinates

Postby Natter » Thu Dec 13, 2018 7:34 am

Thanks it is excellent! But how to make it on a FWH 18.06 ?!
Natter
 
Posts: 1215
Joined: Mon May 14, 2007 9:49 am

Re: GPS coordinates

Postby Antonio Linares » Thu Dec 13, 2018 7:59 am

Code: Select all  Expand view
#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
User avatar
Antonio Linares
Site Admin
 
Posts: 42082
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: GPS coordinates

Postby Silvio.Falconi » 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 November 2023 - January 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
User avatar
Silvio.Falconi
 
Posts: 7053
Joined: Thu Oct 18, 2012 7:17 pm

Re: GPS coordinates

Postby AntoninoP » Fri Oct 16, 2020 1:13 pm

if you want you can try Nominatim with its Web API.
For example
Code: Select all  Expand view
#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
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy

Re: GPS coordinates

Postby Otto » Sat Oct 17, 2020 9:47 pm

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
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6330
Joined: Fri Oct 07, 2005 7:07 pm

Re: GPS coordinates

Postby Cgallegoa » Sun Oct 18, 2020 12:46 am

Otto:

This is correct:
Code: Select all  Expand view
#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-24.07, xHarbour 1.3.1 Build 20240624, Borland C++7.70, PellesC ***
Cgallegoa
 
Posts: 492
Joined: Sun Oct 16, 2005 3:32 am
Location: Quito - Ecuador

Re: GPS coordinates

Postby Otto » Sun Oct 18, 2020 6:55 am

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
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
 
Posts: 6330
Joined: Fri Oct 07, 2005 7:07 pm

Re: GPS coordinates

Postby AntoninoP » Mon Oct 19, 2020 6: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.
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 87 guests