1

I want to use MySQL spatial features to store user location. I have read about MySQL spatial geometry data type. According to this article this works very well in MySQL 5.7 http://mysqlserverteam.com/mysql-5-7-and-gis-an-example/

Have anyone used it and would recommend it? Is InnoDB good engine type for this kind of think? I want this to be efficient, fast and reliable.

What would be the best table structure to store the location? I thought I could do something like that.

CREATE TABLE locations (
    id INT(11) AUTO_INCREMENT,
    location geometry NOT NULL, # I am guessing this will store the latitude and longitude,
    city varchar(100) not null,
    county varchar(100) not null,
    postcode TINYTEXT,
    PRIMARY KEY(id),
    SPATIAL KEY i_location (location)
) ENGINE=InnoDB DEFAULT CHARSET=latin1

CREATE TABLE user_location (
    id INT(11) AUTO_INCREMENT,
    userId INT(11) NOT NULL,
    locationId INT(11) NOT NULL,
    PRIMARY KEY(id)
) ENGINE=InnoDB;

Any thoughts on that?

Then when I will need to use this location for example find users near me within 50 miles. I was thinking to use something similar to examples given in this article http://mysqlserverteam.com/mysql-5-7-and-gis-an-example/

Would that work fast when the database gets huge?

I want to build this solid as I don't want to worry about the speed as the database grows.

Any ideas will be appreciated

EDIT:

I forgot to add that I only want to store UK location

1
  • 1
    I don't know about that one; this one continues to work fast when the database gets huge: My algorithm.
    – Rick James
    Commented Feb 17, 2016 at 6:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.