Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Kunzilla's avatar

Google Maps API (Distancematrix) VS beeline

Hi there,

i've created a platform with geo-informations from user like: User X are 15 kilometers away from User Y. And: Give me users in the distance range from X kilometers. When a user updates his account with zipcode, i fire the Google Maps API (https://github.com/alexpechkarev/google-maps) and save the details in the users table.

So far so good. Now there is a problem with performance and logic.

I can "calculate" the distance with MySQL and get a nearly good result. But thats not the real distance, because its the beeline. When i calculate the distance with round about 500 kilometers, the difference are much high (100 Kilometers)

Alternatively i can use the Google Maps API to get the real distance with driving routes. But that costs time (Request -> Response -> Parsing). When i use this solution, i can work great for single culculations (on the user profile), but when i fire the "Give me users in a distance radius 10 kilometers", i cant show the distance, because it diverges. (Results VS Profile)

Now my question: Is there are pretty clean and fast way to solve this with one solution? I think a Distance Table (User X <-> User Y) can be a possible way, but that feels a way to much i think. AND: If a user updates his GeoData, all the data must be refreshed. I must work well with 10.000 Users.

Hope anybody can help me with that.

0 likes
0 replies

Please or to participate in this conversation.