Last active
October 26, 2021 10:48
-
-
Save sjg/ef74829dfa05388471c5 to your computer and use it in GitHub Desktop.
Spatial Data Capture: Update Photo Locations Fix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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