Skip to content

Instantly share code, notes, and snippets.

@sjg
Last active October 26, 2021 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save sjg/ef74829dfa05388471c5 to your computer and use it in GitHub Desktop.
Save sjg/ef74829dfa05388471c5 to your computer and use it in GitHub Desktop.
Spatial Data Capture: Update Photo Locations Fix
ALTER TABLE photo_locations ADD `points` point DEFAULT NULL;
UPDATE photo_locations SET points = coords;
/* OR If your points coloum in a VARCHAR */
UPDATE photo_locations SET points = POINT(lon,lat);
# MYSQL 5.7.8
# CREATE FUNCTION `distance_old_user`(a POINT, b POINT) RETURNS double DETERMINISTIC
# RETURN ifnull(acos(sin(X(a)) * sin(X(b)) + cos(X(a)) * cos(X(b)) * cos(Y(b) - Y(a))) * 6380, 0);
# MYSQL 8.0.2
CREATE FUNCTION `distance`(a POINT, b POINT) RETURNS double DETERMINISTIC
RETURN ifnull(acos(sin(ST_X(a)) * sin(ST_X(b)) + cos(ST_X(a)) * cos(ST_X(b)) * cos(ST_Y(b) - ST_Y(a))) * 6380, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment