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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

have Bug lat , lng in save #107

Open
vahidalvandi opened this issue Sep 27, 2019 · 15 comments
Open

have Bug lat , lng in save #107

vahidalvandi opened this issue Sep 27, 2019 · 15 comments

Comments

@vahidalvandi
Copy link

vahidalvandi commented Sep 27, 2019

why lan , lng flip in database ? after 3 house research about why geom function not work in sql i found lat , lng is fliped !!!!!!!!!!!!!!!!!!!!1

this create more probleam in use dunction

like
#28

@crynobone
Copy link

State your expected behaviour and actually behaviour. Ranting ain't going to make it easier for others to help or understand you

@vahidalvandi
Copy link
Author

vahidalvandi commented Sep 28, 2019

when store flip in database all query about GIS not work

sample polygon
[
[1,2],
[2,3],
[3,7],
[1,2],
]

after store with eloquent

in database


[
[2,1],
[3,2],
[7,3],
[2,1],
]

i need work point(1,2)

traditional

SELECT
MBRContains(
        area,
        point(1,2)
        )
from masir_area 

i must flip point (very bad) also fliped area

SELECT
MBRContains(
        area,
        point(2,1)
        )
from masir_area 

i create pull request about this

#108

@crynobone
Copy link

https://stackoverflow.com/questions/18636564/lat-long-or-long-lat

POINT(x y)

x usually refer to longitude, and y refer to latitude.

@crynobone
Copy link

To be honest, only this package uses new Point($latitude, $longitude), the underlying jmikola/geojson package that this package depends on new Point([$longitude, $latitude])

https://geojson.org/ format also focus on longitude, latitude.

@vahidalvandi
Copy link
Author

vahidalvandi commented Sep 28, 2019

when we work with google map it show this type
53.859010, -2.810458
lat , lng


usaual (x,y)

also in mysql function such as point(1,2) 1 = x , 2 = y and other like MBRContains search point with this format in polygon [(1,2),(2,3),(1,2)] first item [0] is x


i tested your store type in database and getLat()
$place->point = new point(1,2);

after save in databse in show geom point type === >> point(2 1)
also very Amazing getLat() return 1


why in your document you say
new point($lat , $lng)

??

@vahidalvandi
Copy link
Author

https://stackoverflow.com/questions/18636564/lat-long-or-long-lat

POINT(x y)

x usually refer to longitude, and y refer to latitude.

no

Y = longitude= length &
X = latitude = width

@crynobone
Copy link

Screenshot 2019-09-28 at 8 16 31 PM

https://blog.batchgeo.com/latitude-longitude-map/

But whatever, you seem to be an expert at this and the internet is wrong.

@vahidalvandi
Copy link
Author

see another problem
#30 (comment)

@crynobone
Copy link

see another problem

Screenshot 2019-09-29 at 5 27 44 PM

Have you read about GeoJSON spec? https://macwright.org/2015/03/23/geojson-second-bite.html#position

Screenshot 2019-09-29 at 5 31 20 PM

But again, you are the expect.

@crynobone
Copy link

@vahidalvandi
Copy link
Author

Mr . we must To obey MY SQL Function format . when this package flip x,y in database ST_Contains noooooooot work coreclty

@crynobone
Copy link

when this package flip x,y in database ST_Contains noooooooot work coreclty

I'm using ST_Contains in my project without any bug, everything working correctly.

MySQL is storing the point as POINT(longitude latitude), and POLYGON((long lat, long lat, long lat))

Mr . we must To obey MY SQL Function format

image

https://itnext.io/playing-with-geometry-spatial-data-type-in-mysql-645b83880331

MySQL function comply with POINT(x, y) where x is longitude, and y is latitude. But you keep saying otherwise. So up to you.

@grimzy
Copy link
Owner

grimzy commented Sep 30, 2019

From #30 (comment):

  • when serializing/unserializing the a Point from/to JSON, it uses the GeoJSON format which is (lng, lat)
  • when using serializing/unserializing Point from to string, it uses the Well Known Text (WKT) which is (lng lat)
  • the Point class is (lat, lng)

Same order as Google Maps's Point (lat, lng) because, to me, it feels more intuitive.

@vahidalvandi Since, you've found your bug, it should be a simple matter of reordering the coordinates somewhere in your code.
You can maybe make use of the helpers packaged with this library to convert your input/output.

@vahidalvandi
Copy link
Author

vahidalvandi commented Sep 30, 2019

From #30 (comment):

  • when serializing/unserializing the a Point from/to JSON, it uses the GeoJSON format which is (lng, lat)
  • when using serializing/unserializing Point from to string, it uses the Well Known Text (WKT) which is (lng lat)
  • the Point class is (lat, lng)

Same order as Google Maps's Point (lat, lng) because, to me, it feels more intuitive.

@vahidalvandi Since, you've found your bug, it should be a simple matter of reordering the coordinates somewhere in your code.
You can maybe make use of the helpers packaged with this library to convert your input/output.


we use this package for map like leaflet or google map this maps work with (x,y) =>> (lat,lng)
also mysql function work with point(x y) not >> point(y x) when we run RAW query

@mattvb91
Copy link

mattvb91 commented Jul 1, 2021

@grimzy I think the main confusion here (for me at least). Is that when I have a Point attribute on a model and I paginate that model toJsonthen for some reason the jsonSerializemethod is not called.

Apart from that I do find it confusing on the Point.php

    // line 95
    public function jsonSerialize()
    {
        return new GeoJsonPoint([$this->getLng(), $this->getLat()]); <-- typo or flipped?
    }

but the constructor has them:

    public function __construct($lat, $lng, $srid = 0)
    {
        parent::__construct($srid);

        $this->lat = (float) $lat;
        $this->lng = (float) $lng;
    }

I understand the different formats in the DB etc.. but the json serialize looks off?

EDIT:

I fixed it by appending an attribute on my model and hiding the Point from output:

    public function getLocationAttribute()
    {
        return [
            'lat'  => $this->location_position->getLat(),
            'long' => $this->location_position->getLng()
        ];
    }

I am worried now tho that the further i use this all the mysql functions will be wrong going forward

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

4 participants