Subscribe to this thread
Home - General / All posts - Google Geocode API
cabruce22 post(s)
#01-Jul-24 16:37

I am looking to geocode a database and am trying to use the Google API. I have tried the Restaurants example on YouTube and it works except for returning an Geom. Google API information indicates needing to have a API key to use. How do I include the API key in the SQL code? TIA for any help.

Carlyle

Dimitri


7,464 post(s)
#01-Jul-24 18:25

The example uses a geocoder data source that has already been created (a bing geocoder). You can create a Google geocoder using File - Create - New Data Source - more... and using the [...] browse button next to the Source box to specify your API key. You can then write the SQL code you want that uses that data source.

If you also want to create the new data source using SQL, that's what the Edit Query button is for. Set up the New Data Source dialog as you would above with your API key but instead of pushing the Create Data Source button, push the Edit Query Button, and that will open the Command Window with SQL to create the data source. I just did that using an API key of 12345678 and got the following SQL:

-- $manifold$

--

-- Auto-generated

-- New Data Source

--

CREATE DATASOURCE [Data Source] (

  PROPERTY 'Source' '{ "Source": "https:\\/\\/maps.googleapis.com\\/maps\\/api\\/geocode\\/json?address={address}&key={key}", "SourceAgent": "Mozilla\\/5.0 Manifold\\/9.0", "SourceApiKey": "12345678", "SourceCache": true, "SourceCacheTemp": true,

 "SourceGeocodeReverse""https:\\/\\/maps.googleapis.com\\/maps\\/api\\/geocode\\/json?latlng={lat},{lon}&key={key}"

"SourceGeocodeSearch""https:\\/\\/maps.googleapis.com\\/maps\\/api\\/place\\/nearbysearch\\/json?keyword={query}&type={category}&location={lat},{lon}&rankby=distance&key={key}"

"SourceGeocodeSearchCircle""https:\\/\\/maps.googleapis.com\\/maps\\/api\\/place\\/nearbysearch\\/json?keyword={query}&type={category}&location={lat},{lon}&radius={radius}&key={key}"

"SourceSubtype""google""SourceUuid""e45f498c-9a7d-4d60-a01c-b07626defdf6" }',

  PROPERTY 'Type' 'geocodeserver'

);

(I added newlines in the above to make the code more compact for this forum)

You can then use that SQL to create a data source if you don't want to do it manually. But I'm not sure why you'd use SQL to do that unless you want to automate such things to create a new data source in a project that does not already have one.

cabruce22 post(s)
#04-Jul-24 16:34

Dimitri,

Thanks so much for pointing me in the right direction!

Carlyle

Manifold User Community Use Agreement Copyright (C) 2007-2021 Manifold Software Limited. All rights reserved.