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 (interactive)
- Static API (static)
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
- Very good cards, but not everywhere.
- Bye for free
- API functionality is weaker than Yandex / Google, but can be expanded using Leaflet modules
- But there are floor maps for shopping centers
- api.2gis.ru/doc/maps/ru/quickstart
Azure maps
Mapbox
- docs.mapbox.com/api/maps
- Cute cards for web and mobile.
- I can be mistaken, but the cards seem to be in English only
- For mobile applications, free up to 25,000 users per month, on the web up to 50,000 downloads per month
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
- docs.mapbox.com/api/maps
- I can be mistaken, but the cards seem to be in English only
- Maximum size 1280x1280
- Free up to 25,000 map downloads per month
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
- There is a free rate limited to 25,000 requests per day.
- In addition to the number of requests, it is also limited by the license agreement - the coding results cannot be saved and used without a card (but can be cached), they should be displayed only on Yandex maps and only within the framework of public services (accessible to everyone or with open free registration).
- Works great in Russia, both direct and reverse.
- tech.yandex.ru/maps/geocoder
Tips from DaData
- DaData has a “hint” service that allows you to implement auto-completion of user-entered addresses.
- It includes the functions of a geocoder (it can provide coordinates by address and address by coordinates).
- It works only in Russia, the coating is lame - in millionaires at the level of 75-95%, on average in Russia about 50%
- 10,000 requests per day are free, but the offer does not allow it to be used fully automatically - for standard geocoding you need to use the Standardization service.
- dadata.ru/api/suggest/address
Google Maps Geocoding API
Graphhopper
Mapbox
- docs.mapbox.com/api/search
- The weak base of streets in Russia, at least in Kazan, the streets on which I test - could not find
- Free up to 100,000 requests per month
OpenStreetMaps Nominatim
2 GIS
- The documentation for the Javascript API declared the presence of geocoding functions, but in fact I did not find how to use them in the documentation. Perhaps while it’s under development.
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:
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
- tech.yandex.ru/maps/geosearch
- Up to 500 queries per day are free, provided that the results are displayed on a public map.
- Search results cannot be saved or displayed on maps other than Yandex.
Google places api
- developers.google.com/places/web-service/usage-and-billing
- A very complicated system of tariffing, I did not understand it completely. Perhaps someone who used will write in the comments.
- As I understand it, basic queries are free, but all ext. information (contacts, reviews, ...) is charged separately.
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:
- Building a route from point to point is understandable
- 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.
- 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
- www.graphhopper.com/open-source
- Installs on your server, uses OpenStreetMap to build routes, runs in Java
- There is a free and paid API for those who do not want to install this software on their server.
- There is an API for geocoding, building routes, building distance matrices and optimizing routes, as well as isochrone
MapBox (thanks ne_kotin )
- docs.mapbox.com/api/navigation
- There is an API for geocoding, building routes, building distance matrices and optimizing routes.
- Free up to 100,000 requests per month
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
- developers.google.com/maps/documentation/directions/intro
- The tariff is $ 5 or $ 10 per 1000 requests. 10 - if optimization is used taking into account traffic jams and intermediate waypoints. 5 - if just a route between 2 points.
- By functions, an analog of the Yandex service for building routes between 2 points, but has more settings
- In particular, it can offer several alternative routes.
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
- logistics.2gis.ru
- Service for building routes
- 5 routes a day for 3,500 rubles a month, ready to discuss a limit increase
- For some money, there is tracking of the courier and other additional functions
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.