Creating a google map that shows locations that are stored in a mySQL database on Apache
I would like to create a program that shows locations that are stored in a mysql database on a Google Map. These locations are sp开发者_JS百科ecified in terms of latitude and longitude. Any suggestions? They would be very much appreciated.
There's a good example here. It involves creating XML from MySQL data and using it as a source.
Documentation
you will find in there an example that uses a server on PHP with a mySQL database.
there's also a Flex version.
From the example gallery simple marker example:
var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
//...
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title:"Hello World!"
});
Extrapolating this to a list of locations with lat, long, and description is relatively easy:
var locations = [/*location objects
{lat: -25.123, lng: 131.123, desc: "test" }
... */
var i = 0, maxLoc = locations.length;
for(i=0; i < maxLoc; i++) {
var myLatlng = new google.maps.LatLng(locations[i].lat,locations[i].lng);
//...
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title:locations[i].desc
});
}
You can write the objects to a KML file from your laditude and longitude and feed that directly into the map. Here's how.
EDIT: which language will you be writing your website in? From the MySQL DB I'm guessing you are going to be using PHP. If so, here is how to create a KML file.
精彩评论