Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 19, 2022 12:01 pm GMT

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. The first article in this series shows how to access multiple geocoding providers with a single implementation using Superface OneSDK. Lets now take a look at how can different providers be used based on the country to get the best quality.

Lets say we do some research and determine that Google Maps work better in the US than other providers (this may not be true). And lets 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, wed 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 });

Were 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


Original Link: https://dev.to/superface/using-a-different-geocode-service-for-different-countries-2j07

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To