Does anyone know how to lookup/convert a given address to latitude and longitude?
I've added an amateur log record to my current project and wanted to make it a bit easier to add information. Got everything else sorted on that form but this last bit.
			
			
									
									address to latitude and longitude?
- Fangbeast
- PureBasic Protozoa 
- Posts: 4792
- Joined: Fri Apr 25, 2003 3:08 pm
- Location: Not Sydney!!! (Bad water, no goats)
address to latitude and longitude?
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
						Re: address to latitude and longitude?
Google had a geocode api... https://developers.google.com/maps/docu ... g/overview
If you're after purebasic code...
viewtopic.php?p=494576&hilit=google+geocode#p494576
			
			
									
									
						If you're after purebasic code...
viewtopic.php?p=494576&hilit=google+geocode#p494576
Re: address to latitude and longitude?
Hi,
I usually use something like this:
Originally taken and modified for my use from there (I believe):
viewtopic.php?t=66320
I'm not sure if the structure of addresses is the same in every country (like zipcodes and street names) but it works for my country. Maybe it helps.
			
			
									
									
						I usually use something like this:
Code: Select all
Structure Address
  street.s
  zipcode.s
  city.s
  Country.s
EndStructure
Structure Coordinates
  lat.s
  lon.s
EndStructure
Procedure.i GetCoordinatesFromAddress(*Address.Address, *Coordinates.Coordinates)
  Protected.i HttpRequest
  Protected.s request
  Protected.i json_nr
  Protected.s request_answer
  
  Protected NewList HttpsRueckgabe.Coordinates()
  
  request = "http://nominatim.openstreetmap.org/search/" + URLEncoder(*Address\street + "," + *Address\zipcode + "," + *Address\city + "," + *Address\Country) +  "?format=json&polygon=1&addressdetails=1"  
  
  HttpRequest = HTTPRequest(#PB_HTTP_Get, request,"",#PB_HTTP_NoSSLCheck)
  If HttpRequest
    
    request_answer = HTTPInfo(HTTPRequest, #PB_HTTP_Response)
    
    FinishHTTP(HTTPRequest)
    
    json_nr = ParseJSON(#PB_Any, request_answer)
    If json_nr
      ExtractJSONList(JSONValue(json_nr), HttpsRueckgabe())
      
      If ListSize(HttpsRueckgabe()) >= 1
        ForEach  HttpsRueckgabe()
          *Coordinates\lat = HttpsRueckgabe()\lat
          *Coordinates\lon = HttpsRueckgabe()\lon
          Break
        Next
        
        FreeJSON(json_nr)
        ProcedureReturn  #True
      Else
        ProcedureReturn #False
      EndIf
    Else
      ProcedureReturn #False
    EndIf
  Else
    ProcedureReturn #False
  EndIf
  
EndProcedure
Define MyAddress.Address
Define MyCoords.Coordinates
With MyAddress
  \Country = "Germany"
  \city = "Rust"
  \zipcode = "77977"
  \street = "Europa-Park-Straße 2"
EndWith
If GetCoordinatesFromAddress(@MyAddress, @MyCoords)
  With MyCoords
    Debug "Lat: " + \lat
    Debug "Long: " + \lon
  EndWith
Else
  Debug "Address not found."
  EndIf
  
viewtopic.php?t=66320
I'm not sure if the structure of addresses is the same in every country (like zipcodes and street names) but it works for my country. Maybe it helps.
- Fangbeast
- PureBasic Protozoa 
- Posts: 4792
- Joined: Fri Apr 25, 2003 3:08 pm
- Location: Not Sydney!!! (Bad water, no goats)
Re: address to latitude and longitude?
Thanks Jassing and Fips. Will put this into my bucket of "Must use and bash into my code somehow" s it is needed. Working like a demon most days to finish this damned project and this part is needed.
			
			
									
									Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
						Re: address to latitude and longitude?
Hope it helps -- FWIW -- I live mildly rurally ( about 3 miles outside of a small city in Washignton state, USA; both my suggestion & @fips code failed to locate my lat/lon - despite the USPS being able to ...Fangbeast wrote: Mon Jun 12, 2023 9:58 pm Thanks Jassing and Fips. Will put this into my bucket of "Must use and bash into my code somehow" s it is needed. Working like a demon most days to finish this damned project and this part is needed.
So if you're program is Austrailian-centric - i would look to the government's postal service to see if they provide something. In the USA, the postal service has a web-service that does match my address to an approximate lat/lon.
Re: address to latitude and longitude?
Pb OpenStreetMap should have that
			
			
									
									
						


