Superface Blog
Published on

Using a different geocode service for different countries

Authors
  • Name
    Stephen Mizell
    Social media profiles

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 it 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.

Single SDK for ATS, CRM, SMS and e‑mail APIs

Superface is a single API client for hundreds of APIs. Providing fast, stable, direct API integrations that do not compromise on speed or privacy.

Learn more

API Change Newsletter

Unlike many other APIs, we only publish changes that won’t break your app. However, they might break your world view of APIs!

Superface s.r.o. needs the contact information you provide to us to send you a monthly newsletter. You may unsubscribe from these communications at any time. For information on how to unsubscribe, as well as our privacy practices and commitment to protecting your privacy, please review our Privacy Policy.