Using a different geocode service for different countries

When we want to convert an address into latitude and longitude, we usually have to pick the best provider we can and deal with the varying levels of quality. For instance, sometimes one provider is better than another in a specific area of the world. T…


This content originally appeared on DEV Community and was authored by Vratislav Kopp

When we want to convert an address into latitude and longitude, we usually have to pick the best provider we can and deal with the varying levels of quality. For instance, sometimes one provider is better than another in a specific area of the world. The first article in this series shows how to access multiple geocoding providers with a single implementation using Superface OneSDK. Let’s now take a look at how can different providers be used based on the country to get the best quality.

Let’s say we do some research and determine that Google Maps work better in the US than other providers (this may not be true). And let’s say that we decide to use Google Maps only for US addresses, but Here.com for everywhere else.

We can write a bit of JavaScript to capture this decision.

const providerName = addressCountry === 'US' ? 'google-apis-maps' : 'here';

Normally, after we sign up for accounts for these services, we’d have to find their API documentation, learn how their API works, install their SDKs or build our own integration code, then manage all the differences between them over time. Instead, we can use our OneSDK to make this simpler.

const provider = await sdk.getProvider(providerName);
const result = await profile.getUseCase('Geocode').perform(
  {
      addressCountry: 'United States',
        addressLocality: 'Manhattan',
        postalCode: 'NY 10036',
        streetAddress: 'Times Square',
  },
  { provider }
);

We’re able to interact with both Google Maps and Here.com with less than 10 lines of code, and we can jump between them based on any criteria we choose. In this case, we chose based on the country, but maybe for your case it needs to be something different.

Check out our geocode page to see learn more about using Superface for geocoding.

Read next

This post was originally written by @smizell


This content originally appeared on DEV Community and was authored by Vratislav Kopp


Print Share Comment Cite Upload Translate Updates
APA

Vratislav Kopp | Sciencx (2022-04-19T12:01:32+00:00) Using a different geocode service for different countries. Retrieved from https://www.scien.cx/2022/04/19/using-a-different-geocode-service-for-different-countries/

MLA
" » Using a different geocode service for different countries." Vratislav Kopp | Sciencx - Tuesday April 19, 2022, https://www.scien.cx/2022/04/19/using-a-different-geocode-service-for-different-countries/
HARVARD
Vratislav Kopp | Sciencx Tuesday April 19, 2022 » Using a different geocode service for different countries., viewed ,<https://www.scien.cx/2022/04/19/using-a-different-geocode-service-for-different-countries/>
VANCOUVER
Vratislav Kopp | Sciencx - » Using a different geocode service for different countries. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/04/19/using-a-different-geocode-service-for-different-countries/
CHICAGO
" » Using a different geocode service for different countries." Vratislav Kopp | Sciencx - Accessed . https://www.scien.cx/2022/04/19/using-a-different-geocode-service-for-different-countries/
IEEE
" » Using a different geocode service for different countries." Vratislav Kopp | Sciencx [Online]. Available: https://www.scien.cx/2022/04/19/using-a-different-geocode-service-for-different-countries/. [Accessed: ]
rf:citation
» Using a different geocode service for different countries | Vratislav Kopp | Sciencx | https://www.scien.cx/2022/04/19/using-a-different-geocode-service-for-different-countries/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.