Bertaud
Bertaud

Reputation: 2918

how to draw a rectangle whose the coordinates are stored in a mysql database?

I store my rectangles in the database like so:
1) transfer, by ajax, of the rectangle coordinate to a PHP script;

rectangle.getBounds()  

2) store the rectangle in mysql (with a PHP script)

Now I would like to draw the rectangles stored in mysql database:
1) read the coordinates;

$rectangle = $row['rectangle']    

$rectangle has the following structure ((x1,y1),(x2,y2))
2) transfer, by ajax, to the javascript script.

echo json_encode($rectangle);  

in javascript "$rectangle" becomes "coordinate"
3) finally draw the rectangle

var r = new google.maps.Rectangle({bounds: coordinate, ...});
r.setMap(map);  

Unfortunately a parse error message is displayed instead of rectangles.
Any ideas of my errors ?

Note: hope that this simplified code is understandable. If not I can add code.

Upvotes: 0

Views: 938

Answers (1)

geocodezip
geocodezip

Reputation: 161334

the bounds property of RectangleOptions is a google.maps.LatLngBounds object. You need to convert the value returned from your database into one.

Parse the coordinate values out of the string and use them to create a google.maps.LatLngBounds object.

Upvotes: 1

Related Questions