Web geoservices. Overview of modern solutions





As part of almost any online product, you can meet a task that requires the use of a service related to maps, geocoding, geo-positioning. Personally, I have been working on an online real estate catalog for almost 10 years, and as part of a number of other projects, I have experience using specific functions of various online geo-services.



In this article, I will examine the geo-tasks that are most often faced by programmers, do a short review of the services that offer solutions for these problems, and share my experience of using these services.



I also count on the participation of commentators - if you notice in the review an inaccuracy in the description, the absence of your good service or you just have something to add to what you already wrote - write in the comments, I will collect everything in the main text so that I always have a good list of tools on hand for the future for all occasions.



Table of contents







Display maps on the site



A very popular task is to display online maps on a site. For example, to show exactly where on the map your office is located. Or where you can pick up the thing that the creator of the ad sells.



To display maps, two main types of API are used:





Javascript API



All the services that I developed work mainly with Russia, so I’ll talk about the APIs that I used myself and which are popular with us. I know that bing and other map providers have APIs, but I did not use them.



Javascript API allows you to show an interactive map on the site with the ability to change the scale, display markers, interact with the map (dragging markers, displaying tooltips, etc.).



Javascript API Yandex.Maps





Javascript API Google Maps





2GIS API





Azure maps





Mapbox







Static API



The static API can be used where you need to show just a map picture, without interactivity. For example, you want to attach a map to an email, or allow the user to print a directions to you. Well, or your designer drew a layout in which a map is used instead of the background - loading full JS cards for such a task seems redundant. Also, a static image can be used as a preview to speed up the loading of a page by a user - and by making it interactive.



Static API Yandex.Maps





Static API Google maps





2GIS Static API





Mapbox







Geocoding



Geocoding is a process that allows you to find out the coordinates of an object at its address. Well, or reverse geocoding - find out by coordinates what kind of geo-object is located there. In fact, all geocoding services work with addresses entered in an arbitrary format, at the same time bringing them to their standard. I have not found any completely free geocoding services on the market at the moment.



Typical applications of geocoding are to display the address entered by the user on the map, or vice versa (reverse) - the user put a mark on the map, it must be turned into an address.



Geocoder Yandex.Map





Tips from DaData





Google Maps Geocoding API







Graphhopper





Mapbox





OpenStreetMaps Nominatim





2 GIS









Parse and autocomplete addresses



Sometimes it is necessary to let the user enter an address in a random format, and then turn this address into structured data - separately the name of the country, region, city, street and house number. This is necessary for all services that work with real estate, it is necessary to determine duplicate addresses, to fill out mail receipts, etc.



In principle, all geocoding services from the list above can cope with this task without problems. With direct geocoding, in addition to coordinates, they also return structured information about the found geo-object.



Separately, it is worth noting the "standardization" service from DaData - to addresses from Russia they return a lot of different useful information, 10 kopecks for each address:

dadata.ru/api/clean/address



In addition, to this section I also include the tasks of finding additional information about the address. In particular, this determination of which district of the city the specified address belongs to and the search for the nearest metro stations are important tasks if we search for ads by address.



Definition of the area within the city



At the moment, I have found two solutions for determining the area within the city. Both work only for Russia.



The first and most obvious is DaData. Much has been written about this service, it is really a good service for working with Russian addresses (and this is not an advertisement). Try it yourself, make sure.



If you do not want to depend on a third-party service, there is another solution that I have applied and continue to apply so far. This is the definition of the area by the OKATO address code . Each address within Russia has its own OKATO code - 11 digits. Of these, the first 5-8, depending on the city, clearly indicate the area.



For those cities that I need, I simply compiled a database of OKATO codes for the districts, I got something like this array:



Sample OKATO Codes




The next question is how to find out the OKATO address code? DaData returns it as part of its Tips and Standardization services. There is a site okato-oktmo.rf which at the address shows the OKATO code using the same dadat. Our task is to independently find out the OKATO code at the address, regardless of any service.



To do this, we need to download the latest FIAS database and set up a search on it. There is already an article on the hub with an example of how to import the FIAS database in MSSQL . In general, you configure the search by FIASU, find the address you need there, find out its OKATO code, by the OKATO code from the lists of districts you know the district - that's it, the problem is solved.



If you do not want to take a steam bath with downloading 60 gigabytes of XML files to your database, there is a cheaper, but also less functional than dadata service that allows you to work with the FIAS database:

kladr-api.ru/docs



Search for nearby metro stations



A necessary function, especially for residents of Moscow, when you need to find the nearest metro stations at the address. For this task at the moment I know two solutions:



Yandex Geocoder



First you need to find out the address coordinates. Then, as in reverse geocoding, we transfer these coordinates as request parameters and the type of the returned toponym kind = metro.

A separate parameter sets the size of the area within which it is necessary to search for the nearest station. Empirically, I selected values ​​from 0.02 to 0.05 degrees depending on the city (in Moscow, a radius of 2 kilometers from the metro is still considered walking distance, and in Kazan the distance between stations is 1.5 kilometers).



There is also a problem with this method, that sometimes the nearest metro in coordinates is not always the closest in fact (for example, it is on the other side of the river, or something like that). You can determine the closest metro in terms of accessibility only with the help of services for constructing routes and distance matrices, which will be discussed in the article below. For a rough determination of the nearest station - Yandex geocoder is quite suitable, and allows you to perform up to 25,000 requests per day for free.



DaData



Yes, and DaData can help in this task - as part of the paid tariffs of the “prompt” or “standardization” service, the nearest 3 metro stations and distances to them are also returned to each address.



Search for organizations



A common task if you want to show your customers some kind of organization in his city. For example, you sell goods with delivery, and you want to show the person all points of delivery of some service in his city. Or you make layouts for printing, and show the user on the map all the printing houses where he can go to print your layout.



Yandex search by organization





Google places api





2 GIS



Rumor has it that they have a paid, private API for searching organizations. I have not yet managed to get access to it, and there is quite enough search for organizations from Yandex for our tasks.



User location by IP



A common task on the web is to understand from which city a visitor came to your site. There are solutions for this task in the form of online services or stand-alone solutions for those who do not want to depend on third-party services.



Online service for determining the city by IP - here I can advise (for Russia) DaData again: dadata.ru/api/detect_address_by_ip

The limit is 10,000 requests per day. If your attendance exceeds 10,000 unique entries per day, it makes sense to consider the solutions that are installed on your server. You can read more about them in the DaData review of how they chose what to use.



I will briefly duplicate the information:

IpGeoBase - used to be a good site that was updated daily and provided a database of ip addresses and their respective cities in an understandable machine-readable format that is easily imported into any database. Unfortunately, it stopped updating in 2017.

ipgeobase.ru



SypexGeo - is still being updated, it comes in the form of a php script and a database for it in its own format. Works fast, determines well

sypexgeo.net/en/download



MaxMind offers to download free databases with reduced accuracy and a separate API for them in various programming languages. More accurate databases are available as part of paid products.

dev.maxmind.com/geoip/geoip2/geolite2



Determining the user's location by coordinates



The task is similar to the task of reverse geocoding, with slight differences.



Sometimes we need to determine the user's location when we know his coordinates exactly (for example, we got them using the GPS sensors of the device or the Geolocation API in the browser). There are two options here - reverse geocoding returns the name of the place where the user is located. But what happens if the user is somewhere on the highway between the cities, or in the suburbs or just in a clean field and wants to see ads for the sale of land on this field? Not always the reverse geocoder will cope with this.



In this case, I personally do this - I have in my database all the coordinates of Russian cities in which we have ads and with which we generally work. And according to the coordinates of the user, I simply determine the city closest to him from our database, with a simple request:



ORDER BY (|lng - :lng| + |lat - :lat|) ASC LIMIT 1
      
      







Route building



Sometimes you need to build a route from one point to another. For example, create a location map from the user's location to your office. There are paid solutions from Yandex and from Google - their main difference is that Yandex sells a subscription with an annual payment, and Google charges requests by the piece and deducts money from the card once a month for the month.

Google also has a premium subscription, which provides some additional functions (for example, increasing the maximum size of the Static API image) and a deposit on limits. There is also a solution from 2GIS - the most expensive in terms of 1 route built.



The tasks of building routes are divided into several subtasks:

  1. Building a route from point to point is understandable
  2. The matrix of distances - a service that allows you to build a matrix of distances and time in transit between a set of points of departure and arrival. For example, if you need to calculate the optimal routes for several couriers who need to deliver goods from different warehouses to different customers. Or do you offer cleaning services and you need to find out which cleaner will be more convenient to get to each of today's orders from home and make an optimal scheme for moving the cleaners.
  3. Isochrone API - build around a point area, which can be reached in the same time. For example, "find all the cafes within a 15-minute walk from the user's position."


Different providers offer different solutions for all these tasks.



Thanks to 3aiats , a free Open Source solution was found -

Graphhopper







MapBox (thanks ne_kotin )







Yandex



A common feature of all Yandex services for routes is that they operate in Russia, Abkhazia, Azerbaijan, Armenia, Belarus, Georgia, Kazakhstan, Kyrgyzstan, Moldova, Tajikistan, Turkey, Uzbekistan and Ukraine.



There is an app.swizz.ru service that uses the Yandex API to build routes. The service does not have its own API, and it is experiencing problems with limits from Yandex, but in essence there you can see how the Yandex route builder works. Thank you for the link 3aiats



Google



The main difference from Yandex is Pay-as-you-go pricing, that is, for each request. For small volumes, tariffs will be more profitable with Google, for large - with Yandex.

Also, Google has no restrictions on the countries where they build routes.



Google directions api







Google Distance Matrix API







Google Roads API



A unique Google service that allows you to work with the roads on which your vehicle travels.

Automatically links the points of your route to the roads, shows the best traffic pattern and all the information about the sections of roads that you meet on the way.

It knows how to tie the nearest road sections to the points (for example, using a GPS track that jumps back and forth to show which roads the route was actually crossed).

Able to show speed limits on the roads on the route.







WikiRoutes







Azure maps







2Gis Logistics







Services for optimizing logistics



As a separate class of services for building routes, it is worth highlighting ready-made solutions for optimizing logistics, which are charged based on the number of couriers / vehicles on the line. In fact, they combine route building tools and other services to optimize your logistics as much as possible. These are quite complex and niche solutions, so I combined them into one list.

Thank you for adding to the list 3aiats





Conclusion



In the modern world, you can find a ready-made service for virtually any task that you need to solve, or solve it using a combination of services from the list above. The only question is the cost of this solution, how much it will be beneficial for you.



Many services, as their popularity grows, switch to ever-tougher monetization systems - just as Google's once-free Google maps became completely paid, so Yandex is gradually moving towards this.



There are open OpenStreetMaps, which seem to make you solve all the problems from the list, but for this you need to deploy them yourself, and in addition to your project, separately maintain an entire infrastructure for maps - as far as necessary, everyone decides for himself.



Probably, in the review I did not indicate some excellent services that you use, or you used the services from the review and you have something to add to what has already been written - write in the comments, I will add to the text.



All Articles