View all data on Google Map with image, using PHP,SQL, and XML

View all data on Google Map with image, using PHP,SQL, and XML

, Writer

In this tutorial shows you how to put database table data on Google Map using the PHP SQL and XML. is very simple 1st you have create ab table in your database column like "id, name, type, price, address, image, lat, lng"  and then after use php to make xml API.

Create file fetchXMLdata.php

$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node);
$query = mysql_query("SELECT * FROM room_ad LIMIT 0, 10");
$row = mysql_fetch_array($query);
while ($row = @mysql_fetch_assoc($query)){
$node = $dom->createElement("marker");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("ad_location", $row['ad_location']);
$newnode->setAttribute("lat", $row['lat']);
$newnode->setAttribute("lng", $row['lng']);
$newnode->setAttribute("ad_service", $row['ad_service']);
$newnode->setAttribute("p_img", $row['p_img']);
echo $dom->saveXML();

Checking that your echo XML output works or Not,

If your browser displaying all table marker data from your database as an XML output it means your XML API created successfully then you can use this URL as an API in Map.

<!DOCTYPE html>
<script src=""></script>
font-size: 18px;
font-weight: bold;
color: black;

height: 77px;
width: 97px;
display: none;
<script async defer src=""
<script type="text/javascript">
var customIcons = {
sell: {
icon: '',
shadow: ''

Hostel: {
icon: '',
shadow: ''

rent: {
icon: '',
shadow: ''

function load() {
var map = new google.maps.Map(document.getElementById("map"), {
center: new google.maps.LatLng(-33.863276, 151.207977),
zoom: 6,
mapTypeId: 'roadmap'
var infoWindow = new google.maps.InfoWindow;
// Change this depending on the name of your PHP file
downloadUrl("fetchXMLdata.php", function(data) {
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var name = markers[i].getAttribute("name");
var addressl = markers[i].getAttribute("address");
var address = addressl.slice(0,80);
var type = markers[i].getAttribute("type");
var img = markers[i].getAttribute("img");
var uid = markers[i].getAttribute("url");
var price = markers[i].getAttribute("price");
//var ser = markers[i].getAttribute("ad_service");
var point = new google.maps.LatLng(
var html ="<span class='madd'>" + name + "...</span><img src='' class='mimg'>";
var icon = customIcons[type] || {};
var marker = new google.maps.Marker({
map: map,
position: point,
icon: icon.icon,
shadow: icon.shadow
bindInfoWindow(marker, map, infoWindow, html);
function bindInfoWindow(marker, map, infoWindow, html) {
google.maps.event.addListener(marker, 'mouseover', function() {
infoWindow.setContent(html);, marker);
function downloadUrl(url, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request, request.status);
};'GET', url, true);
function doNothing() {}

  <body style="background:#EEF1F2" onload="load()">

<div id="map" style="width:100%; height:100%; margin-top: -10px;"></div>
var originalLeave = $.fn.popover.Constructor.prototype.leave;
$.fn.popover.Constructor.prototype.leave = function(obj){
  var self = obj instanceof this.constructor ?
    obj : $(obj.currentTarget)[this.type](this.getDelegateOptions()).data('bs.' + this.type)
  var container, timeout;, obj);

  if(obj.currentTarget) {
    container = $(obj.currentTarget).siblings('.popover')
    timeout = self.timeout;'mouseenter', function(){
      //We entered the actual popover – call off the dogs
      //Let's monitor popover content instead'mouseleave', function(){
        $, self);

$('body').popover({ selector: '[data-popover]', trigger: 'click hover', placement: 'auto', delay: {show: 50, hide: 400}});



if any problem to show marker data you can also use Google marker  XML API .

more Details visit on Link.


Comments / Answer

Leave a comment & ask question