Ploting points to Leaflet from MySQL database

3,729 views
Skip to first unread message

Soumaya Lahbib

unread,
Oct 15, 2015, 12:20:30 PM10/15/15
to Leaflet
Hello, 

I have read and spent time looking for solution to plot Lat and Long fields of MySQL DB  into Leaflet map.(I am new to web developement field) and according to what I read I have to :
1. Build my SQL query through php (I can do it)
2. Convert the SQL query result to GeoJSON 
3. Send the GeoJSON to Javascript
4. Plot point to Leaflet map. 

If this workflow is correct, I have no idea how to do 2,3,and 4. 

Does any one have a full example?

Thank you!!


ghybs

unread,
Oct 15, 2015, 12:44:22 PM10/15/15
to Leaflet
Hi,

I think you get the correct flow.

Please have you already looked at this Leaflet tutorial?
http://leafletjs.com/examples/geojson.html

- Step 2: use either PHP or JavaScript to convert the result of your query into a text string / JavaScript object which looks like the example at the bottom of the tutorial. If using PHP to make up a text string, then on your HTML page use JavaScript `yourGeoJsonObject = JSON.parse(yourGeoJsonTextString);` to convert it into an object.

- Step 3: simply use `yourGeoJsonLayer = L.geoJson(yourGeoJsonObject, {onEachFeature: yourConvertionFunction});` as shown in the "onEachFeature" section of the tutorial.

- Step 4: prepare your map as explained in the first tutorial (http://leafletjs.com/examples/quick-start.html) and add your geoJson layer (`yourMap.addLayer(yourGeoJsonLayer);` or `yourGeoJsonLayer.addTo(yourMap);`).

Good luck!

Alexander Kleshnin

unread,
Oct 15, 2015, 1:04:01 PM10/15/15
to Leaflet
Hi!

See code example leaflet-user-map https://github.com/bmcbride/leaflet-users-map by Bryan McBride.
Hope this helps.

четверг, 15 октября 2015 г., 19:20:30 UTC+3 пользователь Soumaya Lahbib написал:

Navnath godse

unread,
Oct 16, 2015, 7:40:55 AM10/16/15
to Leaflet
 HI
 
   Can you tell me how did you do it using php .
 
Thank you!!

Chris Hill

unread,
Oct 16, 2015, 7:52:17 AM10/16/15
to leafl...@googlegroups.com
I wrote a few blog posts about using Leaflet. One that might help you is
http://chris-osm.blogspot.co.uk/2013/11/using-leaflet-with-database.html

--
Cheers, Chris
user: chillly

Soumaya Lahbib

unread,
Oct 20, 2015, 12:06:12 PM10/20/15
to Leaflet
Dear all,
Thank you so much for all your answers and tips. 

To ghybs, Alexander and Chris  : I have read carrefully leaflet Geojson tutorial, blog and looked at the github . I tried to set up all the steps. But I didn't succeed and I am bit in a hurry. 

So, the final solution that I found was to set up a new function and to echo"<script> var map = .........."

Finally it works and I am happy!!! 

Thank you so much everybody

@titanfall

unread,
Oct 21, 2015, 5:02:52 AM10/21/15
to Leaflet
Can u share ur code...

Bay Life

unread,
Oct 21, 2015, 10:45:49 AM10/21/15
to Leaflet
Yeah would also like to take a look at your code. Hanging on the same issue since 6 hours...

Robinson Chera

unread,
Aug 23, 2017, 4:36:00 AM8/23/17
to Leaflet
Hi! Do you have the code? Thanks!

Reply all
Reply to author
Forward
0 new messages