Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latitude / Longitude shouldn't be cast to float values #9

Open
JackWH opened this issue Jul 16, 2022 · 0 comments
Open

Latitude / Longitude shouldn't be cast to float values #9

JackWH opened this issue Jul 16, 2022 · 0 comments

Comments

@JackWH
Copy link

JackWH commented Jul 16, 2022

This is unlikely to affect 99% of developers, but just throwing it out there as a similar issue caught me out before 馃檭

The TarfinLabs\LaravelSpatial\Types\Point class treats latitude/longitude as a float. Most PHP installations will be able to handle up to 11 decimal places (but the precision can vary in php.ini).

However, the POINT type in MySQL supports up to 25 bytes of resolution. So if this package is used against any existing high-precision POINT values, it would lose data when saving the model back to the database.

I think the correct approach would be to use protected string $lat; in the Point class, and construct it with __construct(string|float $lat = 0 ...) etc... The getLat(): float method would still automatically cast as a float before returning, but the toPair() method should be changed to use the original string values of the properties. This would ensure the full precision is persisted back to the database by the LocationCast class.

Again, unlikely to affect most people聽鈥斅爅ust worth mentioning for best practice 馃憤

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant