There’s more than one way to draw a map - Basil Dubyk, Alexander Gaevsky

This video features Alexander Gaevsky and Basil Dubyk at DjangoCon Europe 2020 in Online.

There’s more than one way to draw a map - Basil Dubyk, Alexander Gaevsky
0:32:37
Published October 15, 2020
492 views

DjangoCon Europe 2020 (Virtual)
September 18, 2020 - 10h35 (GMT+1)

“There’s more than one way to draw a map - lessons learned after the Google Maps SDK became unaffordable” by Basil Dubyk, Alexander Gaevsky

The Google Maps SDK: well-known, powerful, and extremely popular - and after July 2018, suddenly unaffordable. We needed to find an alternative for Django geospatial projects. This is the story of our search and what we found, and the lessons that we’d like to share from the experience. The good news is: we returned with new knowledge from our wanderings, and were able to migrate our existing projects successfully.

Summary

A sudden increase in Google Maps API costs led the team to reassess its mapping stack and compare alternatives including OpenStreetMap, TomTom, Mapbox, HERE, GraphHopper, LocationIQ, and others. They chose HERE Maps for its free tier, marker clustering, autocomplete, localization, and coverage, then replaced Google functionality with Vue-based autocomplete, SVG markers, info bubbles, HERE’s clustering strategies, and a custom way to display multiple items at one address. On the backend, they wrapped the small part of HERE’s REST API they needed, added caching for common locations, and showed how Django can support combined full-text and spatial search with PostgreSQL/PostGIS or Elasticsearch. The choice was practical rather than definitive: Mapbox, Leaflet, and other open-source components can be better options depending on requirements and scale.

Key takeaways

  • Mapping services consist of separate tile, JavaScript, geocoding, and reverse-geocoding components, many of which can be assembled from open-source tools.
  • API pricing must be compared carefully because providers count requests, transactions, and credits differently, and free tiers often have usage restrictions.
  • HERE Maps was selected for its clustering support, autocomplete endpoint, localization, coverage, and suitable free tier for the project.
  • SVG markers, browser pixel-ratio sizing, info bubbles, and HERE’s fast-grid and grid clustering strategies improved the frontend implementation.
  • A small REST wrapper was sufficient for the backend, while caching common locations reduced repeated lookups.
  • Django applications can combine text and geographic search using PostgreSQL with PostGIS or Elasticsearch, depending on the project’s needs.

Summarised automatically from the transcript.

Chapters

  1. 0:00 Introduction and Google Maps Costs The presenters introduce their work and explain why rising Google Maps costs prompted a search for alternatives.
  2. 2:25 Components of a Mapping Service An overview of tile servers, JavaScript map libraries, geocoding APIs, and open-source building blocks.
  3. 4:45 Mapping Service Selection Criteria The talk defines requirements including pricing, clustering, geocoding, autocomplete, localization, and performance.
  4. 6:19 Mapping Provider Comparison OpenStreetMap, TomTom, Mapbox, HERE Maps, GraphHopper, LocationIQ, and other services are compared.
  5. 16:18 Choosing HERE Maps The presenters explain why HERE Maps was selected as the replacement for Google Maps.
  6. 19:00 Address Autocomplete Migration The frontend implementation of address autocomplete with Vue and the HERE Maps API is presented.
  7. 21:20 Markers and Info Bubbles The talk covers custom SVG markers, high-DPI sizing, informational pop-ups, and map styling.
  8. 23:40 Marker Clustering Strategies HERE Maps clustering algorithms are compared, including fast grid, grid, and dynamic grid approaches.
  9. 26:02 Multiple Items at One Location A replacement for spiderfied markers is implemented using a single marker and navigable information pop-up.
  10. 27:47 Backend Geocoding Integration The presenters describe replacing the Google Maps Python SDK with lightweight HERE Maps REST API integration and caching.
  11. 29:18 Spatial Search with Django Spatial and full-text search implementations using PostGIS or Elasticsearch are demonstrated.
  12. 31:34 Alternative Mapping Libraries The talk concludes by noting viable alternatives such as Mapbox Supercluster and Leaflet MarkerCluster.

Questions this talk answers

What parts make up a mapping service?

A mapping service generally consists of a tile server, a JavaScript or other front-end map library, and geocoding and reverse-geocoding APIs. The talk also points to open-source options for building each component yourself.

Discussed at 2:25

What should I compare when choosing a Google Maps alternative?

The relevant criteria include pricing and free quotas, customizable markers and clustering, forward and reverse geocoding, autocomplete, localization and data accuracy for the target region, SDK availability, and performance with large numbers of markers.

Discussed at 4:45

Which Google Maps alternative did they choose for their Django project, and why?

They selected HERE Maps because it offered built-in marker clustering, a generous free tier, and a dedicated autocomplete endpoint that fit their existing platform. Its location coverage and data sources also supported their requirements for Germany and Austria.

Discussed at 16:18

How do you implement address autocomplete with HERE Maps and Vue?

Because HERE Maps did not provide a ready-made autocomplete JavaScript component, they built one with Vue: an input sends configurable requests to the HERE API, displays the returned labels in a dropdown, and uses the selected location ID to retrieve coordinates or details.

Discussed at 19:00

How can I improve the performance of map marker rendering?

The presenters replaced transparent PNG marker images with SVGs and configured the marker size and anchor point based on the browser’s pixel ratio. This improves rendering and keeps markers correctly sized on high-DPI displays.

Discussed at 21:20

Which HERE Maps clustering strategy should I use for many markers?

HERE Maps provides fast-grid, grid, and dynamic-grid strategies. They used fast grid for large search-result datasets because it initializes clusters much faster, grid where greater precision matters, and did not use dynamic grid because their markers were not updated after being placed on the map.

Discussed at 24:26

How can I show multiple items at the same address on a map?

Instead of displaying overlapping markers, they show one marker for the address and put all available items in the marker’s information window, navigable with arrows. They found this easier to use than a spiderfied group of markers, where users could accidentally skip items.

Discussed at 26:02

How do you use HERE Maps from a Python or Django backend without a Python SDK?

A native Python SDK is not required: the backend can wrap the HERE REST API directly. Their implementation only needed endpoints for geocoding, reverse geocoding, and location lookup, with optional caching for frequently requested locations.

Discussed at 27:47

How can I implement combined full-text and spatial search in Django?

The talk presents two approaches: PostgreSQL with PostGIS and GeoDjango, or Elasticsearch with Django Haystack. Both are exposed through Django REST Framework, using geographic-distance filtering alongside text-search queries.

Discussed at 29:01

Open full transcript Markdown

Transcript

3,778 words · auto-generated · en Show transcript

Automatically transcribed, so expect mistakes in names and technical terms.

Speaker 1

Hello everyone. Our talk is there's more than one way to draw a map. We're Metaclass Agency. I'm Aleksandr Gayevsky, this is my colleague Basil Dubik. Hi We're developing custom solutions for e-commerce, fintech, and other domains using Python 3, Django, and also Flask and FastAPI. In our spar time we contribute to the open source projects like Django Oscore and Django. This year we're giving a talk from my living room, not for the conference call, and this is kind of a weird experience Third party special services are key parts of the

worst platforms in different domains. And traveling at delivery peer-to-peer marketplaces, transportation. And Google recommended itself as a liable and solid provider, making itself practically irreplaceable part of those services. As time goes by and special integration becomes more and more tight. We were busy shipping fishes for the client project when in the early fall of 2018 our client approached us since the bill for the Google Mass API. Dramatically grew. Until July 16, 2018

, 1000 additional requests after initial quote of 25 A thousand of requests cost 50 cents and it grew to $7 afterwards. Not that we weren't satisfied by the Google Maps but then But the estimated costs exceed the client expectations and our budget, so we started to seek for the solutions. and prove this prove the existence of full-fledged flexible and powerful alternative of Google Maps which Django spatial project could use And also the current price spike not only made us to start looking for a placement but also to

re-evaluate the whole approach of external API usage and free API limits more carefully. So but before we go and review alternatives, let's see what special and pattern service consist of So first of all it's tile server which renders map tiles and serves them Also it's JS or other front-end library which allows to read the whole map out of the tiles and display in the browser. And geocoding API which allows you

to get the place get the location coordinates and other geodata and also reverse geocordinate which allows vice versa get their location name from the coordinates Basically, nowadays there are open source components which allows you to build all of the parts of the special service for the tiles server you could use Tigola open map tiles or you could use OS to PGL Component by OpenStreetMaps,

modile for the Apache or custom solution by for the Flask. to render the to serve the tiles and mapnik to render the tiles of the server There are also plenty JS map libraries, decent ones, like Leaflet JS, Open Layers. And pubbox gel I would mention those ones. Also there are geocoding API servers like Pilias and Nominating Let's see what alternatives we have.

OpenStruet maps, mapbox tom, here maps, location IQ, graphhopper So first of all, the criteria for the service was reasonable pricing and a sufficient free ETF. And map widget, customizable markers and informational model which could display some additional data when you click on the marker And we had plenty of markers on the map already, so we needed to group them into the cluster which we already had in the Google Maps.

As for the geocoding we needed both forward and reverse geocoding. Last but not least we use location autocomplete and it would be nice to have a similar one on this new service as well and a native python sdk would be cool as well also, our client platform focuses on the clients in Germany and Austria. So we wanted that. The special data for those locations is

maximum accurate and also we needed all labels and everything to be localized in German. And we already had 10,000 of markers and maps, so rendering clusters also needed a good performance. Otherwise customers would be Frustrated and open map follows too slow. So OpenStreetMaps is a good is a decent service which uses open data And it's also open source and it has pre free pricing. Already it has the Python SDK, GSmap CSDK compatible with it, and the RESTful

API and on the on dataset which is crowdsourced by the users and it has localization The only con is that the data is open and free, but server is not services usage is not free. And then their services run entirely on donated resources and they have limited capacities. So basically you as soon as you reach the quote, which is n they don't have a hard quote, but as soon as you utilize their services too hard

They would block requests. And they suggest you to deploy your own tiles server using for instance OpenMap tiles. So next alternative is TomTom. TomTom is Dutch GPS navigator manufacturer, which is widely used in the UA and European Union and North America and navigation the mass software producer. It has a three tier for two thousand five hundred requests per day which is seventy-five thousand requests per months and limitation of five requests per second for non-tile-based APIs

and 1000 for tile bell tile-based APIs And flexible pricing you can pay as you grow more quests more costs Although there are some qubits here, one requests equals one transactions, but not always accept traffic API tiles and so on and so on. They have a native SDK for Android, iOS, and web and it supports Marcus and Marcos clusterization

RESTful API has forward and reverse geocodian search and the dedicated endpoint for after complete and it has localization And uses own dataset Mapbox allows to use map fifty thousand times for free and it allows to do one hundred thousand requests to the temporary geocoding api and five hundred thousand Up to 500,000 requests to permanent GeoCode and API.

It has Python SDK, but it's not currently actively developed and for now It has mobile SDK for IS and R8. It has augmented reality SDK And it has a RESTful API with both forward, reverse geocoding and autocomplete. And it has localization as well. HereMap the HereMaps it's a service run by Here Technologies, which is a Netherland-based international technology company previously It was Nokia Maps or OVMaps. It's now owned by a group of

companies which are mainly automotive. Such as Audi, BMW, and Aimler. Her maps were used by Facebook and by Microsoft Maps. So the pricing is two hundred thousand a transaction per month. It has five thousand mobile sdk mostly active users and it doesn't have a mobile native Python SDK, it has JavaScript SDK for building maps

And extensive restful API for allocation discovery and geocoding back both forward and reverse I would suggest location browsing lookup by d reverse geocoding and localization Graf Hopper. Graf Hopper is a German service for road planning and optimization. And his it's my foc focus on this functionality. It has free tier of 500 crits per day, but only for non-commercial use.

It has limited radio account per minute and cannot use flexible mode Doesn't have native Python SDK, doesn't have maps. sdk, and doesn't have dedicated up to complete endpoint The dataset is provided by multiple sources and depends on the source you will be built a different amount of credits. Location IQ. Location IQ and has a free tier of ten thousand requests per day

or two requests per second or sixty requests per minute, which leads to three hundred thousand requests per month and it has limited commercial use so you need to add the link to the location qcom site in the application or on your on your site So it has and it has bunch of native software development kits for python, C sharp, Dart, Ruby, Objective-C, Perl. Kotlin, PHP, Swift, Scala, Rust, Java, Haskell, R Go, C, and Clujo.

It doesn't have own maps JavaScript SDK and mobile SK as well. Although it has forward and revest geocoding and location search and dedicate it endpour after complete. It has localization, but since it depends on the external data providers like open street map street map If the if the data provider translated particular G data into the local language. It will be translated on the local location IQ

as well. But they don't guarantee that all results will be translated A D A D is a Dutch service. It has a free tri of ten thousand requests per month. It doesn't have any SDKs, but it has powerful and dedicated map tile server. and RESTful API for forward and report your coding but does it have dedicated point for after complete joke. Joke maps is a French service

Which does not have a which has free pricing only for commercial only for non-commercial use it's 50 thousand map use ten thousand static maps you and ten thousand place search requests Doesn't have any SDKs natively. Respole API has a forward, reverse geocoding allocation search and dedicated endpoint for after compute. and localization the dataset they are using is from open suite maps open addresses and your

names So there is a precaution that the credits and transactions and requests it's not all the same when you choose the service you need to carefully I read the agreement and the terms of use because some of the requests to the APIs would cost a few credits And consequently they will be built not as one of course but as multiple Finally, we selected HereMaps as the replacement of the Google Maps first of all because it has a built-in marker clustering

Which would allow us quickly to switch to the here maps and to save our clusters It has generous free tier and it has dedicated autocomplete API endpoint, which we use in two places in our platform. Dedicated AP endpoints allow you to fetch results Only to fish results and only receive the full location names and location IDs, just the minimum amount of information and to

Later on retrieve the details of this particular location. So also based on the Counterpoint research company, Here Technologies was named as the world's number one location platform and it has leading position during the last three years. Here maps Has eighty thousand sources of data and provides maps in one hundred ninety countries in the world. So

Finally auto's combination of the criteria made us choose the here mass. So yeah and yeah we could now proceed with the immigration and my colleague would tell you about it

Speaker 2

As you may know, with Google adding address autocompletion is quite easy since you just need to include their JavaScript library into your HTML and provide some callback. for when the selected address is changed. This is general everything that you need to do to make it work. I mean that you are fine with the default styling But this is not the case with here maps. They do not provide ready-to-use JavaScript library for these. And so since we already use view framework in many places in the project, we decided to implement after completion with view, means like making requests, showing drop-down, etc. For this, as you can see on the slide, we use simple input to get

the place required by the user for the search and initial value for it will be rendered by the Django and not by view. In the request, in general in the query string, in the request for the here maps API, it's possible to set many different settings that required by a project and for example like result results language and the countries that will be used for the search and the max result and similar thing And also, this I think is very important, you can indicate what HTML tag will be used to highlight the to highlight the results with places that match

text typed by the user Here you can see the example of suggestions from the maps API. From here, in general, we use just label to show in the drop-down and location ID that we use to. Get coordinates of the place. When the user adds their equipment to the platform, they can use address autocompletion to select like concrete address but when we use autocompletion for searching equipment in desirable areas we limit the results To the ones where only the CT matches with the text entered by the user, and you can see this filtering on the slide.

Now we are talking about how we Draw and use markers. As you know, Google Maps as well as Here Maps allow you to use custom images for the markers So the simplest what we can do for the start, we just use the same image for the icon that we used previously with Google Maps, we use the same for the here maps. But we found that performance is not quite good because we use like fancy PNG with transparency and other. So we decided to use SVG instead of. P

G and additionally and additionally here now we start to set the marker size and other things. The time we That time we decided to use SVG instead of PNG to improve the performance of marker rendering and with SVG icons for markers, we started to indicate needed marker size and anchor point Now the size of markers depends on the user browser's pixel ratio, and this is very useful to show markers in correct size on high DPI and routine displays. To show additional info

when a user is clicking on the marker, it's possible to use info bubbles. For it, you just need to provide the coordinates and the HTML content. And here's an example of an info bubble is very simple, but It showed that you can display all data related to the clicked point on the map. In our case, we shows a photo of the equipment, user's profile picture, and Score, price, etc. It's possible to style content in the info bubbles by updating CC's classes added by Info bubble automatically and by styling custom CCS classes inside the info bubble

And additionally, to you can customize your map during initialization by setting needing tiles. And we think that this is very customizable, so probably can be used in any range of requirements. However, after the first part was finished, a trickier one popped up, marker's clusterization. This metal allows to group markers of one location, hide single markers and show a group of markers instead for the given scale. When the users close down, group breaks down into the other groups or to the separate markers. Google Maps provide a ready-to-use JavaScript library in the official repo

and a couple of examples how you can use it and integrate. Our successor here maps luckily has built-in markers clusterization under the hood and three different algorithms. or strategies powering it. It's first grid, grid, and dynamic grid for different for different dataset sizes. And we can compare them The fast grid is an efficient way to cluster large sets of data points, and we use it for the pages where we show search results. not related to some like concrete place or when we show all the markers on the map. Grid strategy is slower but has greater precision.

We use it for maps on the user's profile pages. And dynamic grid clustering uses the same algorithm of clustering as the grid, but clusters on the viewport basis. It was suited for data sets that are subject to frequent updates and we don't use it in our project since we do not make Updates to the map since we put all the needed markers to the maps once. We made our own comparison for the different strategies and we can see that Fast grid strategy a lot for a lot of markers, clusters appear on the initialized map much faster than with grid

strategy. Last but not least, we have multiple different equipment items tied to the same address. So that previously we plugged it. In an additional JavaScript library which renders markers within the same location as a literal web of markers. With Spiderfire we used markers in the open cluster as single markers on click we show an info window. Since here does not Provide the same functionality as Spiderfire. This time we used a different strategy. We just decided to display only one marker and show available gear in the informational

pop-up. Which appears when the user clicks on a marker. Now in the info window for the cluster, the user will be able to review all the gears by using just arrows. We found this solution even better. Than what we have with Spider Fire, since previously users can accidentally skip some markers in the open Spider-Fire, if there are many of them, they are all the same in general, and now this is not possible And additionally, we can say that it's possible to use custom cluster icon. In general, cluster icons can be the same as the marker icons, but since cluster groups a couple of

Markers, it's useful to show number of markers in the group. And we have achieved this by putting just text part into our SVG template.

Speaker 1

Now that we have finished with the front end migration, we can look at the back end On the back end we were using native Python SDK for Google Maps and now we obviously needed SDK replacement for here maps. It doesn't have Python decay, but it's not necessary after all. We can quickly wrap around the RESTful API Since we only need three endpoints for geocoding, reverse geocoding and location lookup. Also, there is a nice looking third-party package called Herepy which is also suitable for here integration although we use only three endpoints

Which doesn't seem enough for bringing in another dependence on board As stated before, auto-suggest endpoint basically returns only location IDs and has minimum information about the location. Obviously due to the performance reasons so we can later on through location details separately naturally there are popular locations big cities like Berlin Colonia Munich which customers often look for equipment around and in order to utilize a pick what more wisely we could cache allocation data for those

locations and you can see on the slide This cache implementation in the lookup method. Now we could review some advanced features like spatial search for the Django project. We have s have a similar one on our platform as well So there were choice two choices to implement full text at the same time full text and spatial search in the Django project. You could use Postperscale as the database engine or

Elasticsearch. So For the PostgreSQL, for the post SGRSQLE, you would need PostGIS and obviously Joe Geojle And on the slide you see that we outlined the simple model and implemented Yan. Simple endpoint for the junk rest framework which is doing queries in search filter and also special search using divisin

Filter The implementation for the Elastic requires also a Django has tagged, and on the slide you see that we outline the index class for the Django Hastack and the implementation for the Django Rest framework it looks quite similar except the queer set we use a separate method d within not filter and the parameters Are quite similar. All in all, we don't stick to the

your maps as the ideal solution since there are plenty of decent products available and we can't avoid mapbox who build special JavaScript library supercluster which shows quite decent performance with millions of points in the dataset Also, the Leaflet has a marker cluster module which also allows to build a cluster for then markers. Thank you very much for listening.

You can ask your questions or contact us in the twitter or via the email.

Conference

DjangoCon Europe

September 18 - 19, 2020

Online

Note: We understand that names change, people change, and bodies change. We respect each individual's journey and privacy. If you have any concerns about a video or need us to remove content, please don't hesitate to contact us. We will handle your request with care and promptly address any issues.

More videos from DjangoCon Europe