Dynamic google maps markers

General discussions related to php

Moderators: macek, egami, gesf

ale371
New php-forum User
New php-forum User
Posts: 1
Joined: Thu Jun 07, 2012 3:37 am

Dynamic google maps markers

Postby ale371 » Thu Jun 07, 2012 3:43 am

Hi Everyone, i'm quite a noob in PHP but i'm trying to incorporate a little map showing the place marked by coordinates stored in my db
i'm in a while cycle that examinates if there's still entries (while(pg_fetch....) and in an if that check if the entry is a "place" type caracterized by latitude and longitude vars...

Does anyone know how to do so? i've tried with javascript but i don't know it and i encountered many issues (and still don't work)


here's the code i made

Code: Select all

[...ETC...]
if($row[0]=="place"){
            $query2="SELECT lat, longit ,tempo, segnalazioni
                  from cinguettio
                  where id='$row[4]'AND creatore='$row[10]'";
            $query2_res = pg_query($con, $query2);
            $row2 = pg_fetch_row($query2_res);
$lat=$row2[0];
$long=$row2[1];
   echo"<tr height=50 bgcolor='#E0F0B0'><td bgcolor='#E0F0B0' width=600><b>";
   echo "<b>".$row2[0].", ".$row2[1];
   ?>
    <div id="map" style="width: 500px; height: 400px;"></div>

  <script type="text/javascript">
 var locations = [
       ['Siamo Qui', <?php echo $row2[0];?>, <?php echo $row2[1];?>, 1]
    ];
       var map = new google.maps.Map(document.getElementById('map'), {
      zoom: 10,
      center: new google.maps.LatLng(<?php echo $row2[0];?>, <?php echo $row2[1];?> ),
      mapTypeId: google.maps.MapTypeId.ROADMAP
    });

    var infowindow = new google.maps.InfoWindow();

    var marker, i;

    for (i = 0; i < locations.length; i++) {   
      marker = new google.maps.Marker({
        position: new google.maps.LatLng(locations[i][1], locations[i][2]),
        map: map
      });

      google.maps.event.addListener(marker, 'click', (function(marker, i) {
        return function() {
          infowindow.setContent(locations[i][0]);
          infowindow.open(map, marker);
        }
      })(marker, i));
    }
  </script> <?php
[... ETC...]

Return to “PHP General”

Who is online

Users browsing this forum: No registered users and 2 guests