Playing with Geometry/Spatial Data Types in MySQL

In this tutorial, we are going to understand how to store and use spatial data types like coordinates and objects. But, we will mainly focus on Points (2D Cartesian Coordinate) and Geographic Locations (Geodetic Coordinates)

Uday Hiwarale
System Failure

--

(courtesy of pexels.com)

Imagine that you are trying to develop an application that helps people find restaurants, pubs, bars and other hangout places near them. In nutshell, this will be a location discovery platform.

Looking from a backend perspective, we would be needing to store geographic data of these locations like Latitude and Longitude. Then we would need to write functions that calculate the distance between the user and the location (to show how far the location is from him/her). Using the same function, we can design an algorithm that finds closest places near to the user or within a given radius from him/her.

There are many tutorials and study material on the internet that helps you solve this problem by using simple data types like float for latitude and longitude and MySQL’s capability to create internal procedures/functions to calculate & search locations. But in this tutorial, we are going to talk about MySQL’s built-in spatial data types.

--

--