Show Markers on google map by using data from mysql in php

Virendrasingh

I attached image here for an example.I want that the location with marker and it's description will show something like this in map but from MySQL database with php. so, if some new stores is added then i quickly update it from DB.

Currently I show locations on map in a HTML page with static code like,

Java scripts to load map on page :

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=true"> </script>

 <script type="text/javascript">
   var map;
   var centerPos = new google.maps.LatLng(37.0902,95.7129);
   var zoomLevel = 4;
   function initialize() 
    {
      var mapOptions = 
      {
       center: centerPos,
       zoom: zoomLevel
      };
      map = new google.maps.Map( document.getElementById("map-canvas"), mapOptions );
    }
    google.maps.event.addDomListener(window, 'load', initialize);
  </script>

Google map Div :

    <div id="Community-Google-Map-Div">
          <div class="wrap">
            <div id="map-canvas">
            </div>
          </div>
    </div>

Java scripts to load Different locations :

  <script type="text/javascript">

    function LocateSales() 
    {
      var map;
      var centerPos = new google.maps.LatLng(22.4700,77.5667);
      var zoomLevel = 4;

      var mapOptions = 
      {
        center: centerPos,
        zoom: zoomLevel
      };
      map = new google.maps.Map( document.getElementById("map-canvas"), mapOptions );

      var locations = [ ['USA', 50.0000, 79.7800],
                        ['Second', 82.9667, 77.5667],
                        ['Third', 78.4700, 77.0300]
                      ];

          for (i = 0; i < locations.length; i++) {  
          marker = new google.maps.Marker({
      position: new google.maps.LatLng(locations[i][1], locations[i][2]),
      title: locations[i][0],map: map });
       }
  }
   google.maps.event.addDomListener(window, 'load', initialize);
  </script>

So, Please tell me how to solved this !

Virendrasingh

Thanks everyone for your response but I got answer. I post it here,

<?php
error_reporting(E_ALL ^ E_DEPRECATED);

$conn = mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("slcommunitydb") or die(mysql_error());
?>

<html>
<head>
 <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Google Maps</title>

<!-------- Customizable Css for Map  ----------------------------->
    <style type="text/css">
        body { font: normal 10pt Helvetica, Arial; }
        #map { width: 500px; height: 300px; border: 0px; padding: 0px; }
    </style>

    <!---------------- Java Scripts for Map  ----------------->
    <script src="http://maps.google.com/maps/api/js?key=xxxxxxxxxxxxxxxx&sensor=false" 
    type="text/javascript"></script>

    <!------------- Java Scripts for Map  ------------------->
    <script type="text/javascript">

    //--------------------- Sample code written by vIr ------------
    var icon = new google.maps.MarkerImage("http://maps.google.com/mapfiles/ms/micons/blue.png",
               new google.maps.Size(32, 32), new google.maps.Point(0, 0),
               new google.maps.Point(16, 32));
                    var center = null;
                    var map = null;
                    var currentPopup;
                    var bounds = new google.maps.LatLngBounds();
                    function addMarker(lat, lng, info) {
                        var pt = new google.maps.LatLng(lat, lng);
                        bounds.extend(pt);
                        var marker = new google.maps.Marker({
                            position: pt,
                            icon: icon,
                            map: map
                        });
                        var popup = new google.maps.InfoWindow({
                            content: info,
                            maxWidth: 300
                        });
                        google.maps.event.addListener(marker, "click", function() {
                            if (currentPopup != null) {
                                currentPopup.close();
                                currentPopup = null;
                            }
                            popup.open(map, marker);
                            currentPopup = popup;
                        });
                        google.maps.event.addListener(popup, "closeclick", function() {
                            map.panTo(center);
                            currentPopup = null;
                        });
                    }           
                    function initMap() {
                        map = new google.maps.Map(document.getElementById("map"), {

                            center: new google.maps.LatLng(0, 0),
                            zoom: 14,
                            mapTypeId: google.maps.MapTypeId.ROADMAP,
                            mapTypeControl: true,
                            mapTypeControlOptions: {
                                style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR
                            },
                            navigationControl: true,
                            navigationControlOptions: {
                                style: google.maps.NavigationControlStyle.ZOOM_PAN
                            }
                        });
     <?php

     $query = mysql_query("SELECT * FROM salesmapmarkers")or die(mysql_error());
    while($row = mysql_fetch_array($query))
    {
      $name = $row['name'];
      $lat = $row['lat'];
      $lon = $row['lon'];
      $desc = $row['desc'];

   echo("addMarker($lat, $lon, '<b>$name</b><br />$desc');\n");
   }
  ?>
   center = bounds.getCenter();
   map.fitBounds(bounds);

   }
   </script>

  </head>
    <body onLoad="initMap()" style="margin:0px; border:0px; padding:0px;">
       <div id="map"></div>
    </body>
 </html>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Show Markers on google map by using data from mysql in php

From Dev

Displaying google map with markers using data from mysql (laravel)

From Dev

Google Map Direction using data from mysql

From Dev

Android Google Maps v2 add Map markers from JSON array php mySQL

From Dev

Android Google Maps v2 add Map markers from JSON array php mySQL

From Dev

Google map to display many markers dynamically using php and jquery

From Dev

Asynchronous loading of Google Map Markers from Json data

From Dev

Asynchronous loading of Google Map Markers from Json data

From Dev

How to get Google map Markers from URLs using asynctask?

From Dev

Android Google Map show markers on zoom change

From Dev

Google Maps - Show many markers in a map

From Dev

Drawing markers on map using data retrieved from my database

From Dev

Show all data from Mysql Database by category wise using php

From Dev

Grab complex data from mysql and show them using php

From Dev

Show data from database to Array Multidimensi using php and mysql

From Dev

How to show the markers, some distance from the map

From Dev

How to load markers from MySQL using PHP and ajax?

From Dev

How to load markers from MySQL using PHP and ajax?

From Dev

Android - google map - how show multiple markers on the map?

From Dev

Google maps show multiple markers from firebase

From Dev

Markers not displayed in the google map using JSON

From Dev

Toggle markers in google map using radio button

From Dev

python folium map markers do not show on map despite data

From Dev

markers on google map from array list

From Dev

markers on google map from array list

From Dev

PHP: Show data from mysql database in table

From Dev

Can't show google maps android markers from coords stored in mysql db

From Dev

Populate Google Map Markers using MySQL, JSON and jQuery plugin Gmap3

From Dev

Get array of coordinates from mysql database and add as markers to Google map in android

Related Related

  1. 1

    Show Markers on google map by using data from mysql in php

  2. 2

    Displaying google map with markers using data from mysql (laravel)

  3. 3

    Google Map Direction using data from mysql

  4. 4

    Android Google Maps v2 add Map markers from JSON array php mySQL

  5. 5

    Android Google Maps v2 add Map markers from JSON array php mySQL

  6. 6

    Google map to display many markers dynamically using php and jquery

  7. 7

    Asynchronous loading of Google Map Markers from Json data

  8. 8

    Asynchronous loading of Google Map Markers from Json data

  9. 9

    How to get Google map Markers from URLs using asynctask?

  10. 10

    Android Google Map show markers on zoom change

  11. 11

    Google Maps - Show many markers in a map

  12. 12

    Drawing markers on map using data retrieved from my database

  13. 13

    Show all data from Mysql Database by category wise using php

  14. 14

    Grab complex data from mysql and show them using php

  15. 15

    Show data from database to Array Multidimensi using php and mysql

  16. 16

    How to show the markers, some distance from the map

  17. 17

    How to load markers from MySQL using PHP and ajax?

  18. 18

    How to load markers from MySQL using PHP and ajax?

  19. 19

    Android - google map - how show multiple markers on the map?

  20. 20

    Google maps show multiple markers from firebase

  21. 21

    Markers not displayed in the google map using JSON

  22. 22

    Toggle markers in google map using radio button

  23. 23

    python folium map markers do not show on map despite data

  24. 24

    markers on google map from array list

  25. 25

    markers on google map from array list

  26. 26

    PHP: Show data from mysql database in table

  27. 27

    Can't show google maps android markers from coords stored in mysql db

  28. 28

    Populate Google Map Markers using MySQL, JSON and jQuery plugin Gmap3

  29. 29

    Get array of coordinates from mysql database and add as markers to Google map in android

HotTag

Archive