MySQL Forums
Forum List  »  GIS

Re: Using MySQL Spatial Extensions to make a Google Maps interface.
Posted by: Clive Galway
Date: August 24, 2005 04:33AM

Data for plotting is passed to Google Maps as Longitude, Latitude pairs.
Spatial data types are not actually needed to do this, you could actually have a FLOAT field for Lng and Lat.

However, having FLOAT fields for Lng, Lat means that you cannot store a line in the same field as a point, which is the main reason I switched to MySQL 4.1's Spatial Extensions.

I now use a field "point" of type GEOMETRY.

A GEOMETRY field can hold lines or points in the same field.
To enter data in to the GEMOMETRY field you use something like INSERT INTO.... GeomFromText(mydata) .....

To read the data out you would use something like SELECT *, AsText(point) AS pointstr .... WHERE.....

The Text (WKT) representation of a point is like POINT(0.12345 1.23456) and the WKT representation of a line is like LINESTRING(0.12345 1.23456, 2.34567 3.45678)

To query data:
To find all points that fall within or touch a box (ie the viewing area):
SELECT *, AsText(point) AS pointstr .... WHERE Intersects (pointstr, GeomFromText('0.123456 1.23456,2.345678 3.456789,4.567890 5.678901,6.789012 7.890123)'))

All of this was researched from http://dev.mysql.com/doc/mysql/en/spatial-extensions-in-mysql.html - it made it quite clear enough even for an amateur like me :)

You can always dissect my source code, you want to look in gmaps_xmb_xmlgen.php

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.