Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    May 2007
    Posts
    162
    Thanks
    13
    Thanked 0 Times in 0 Posts

    google maps polyline/mysql php question

    I'm trying to insert polylines onto google maps using coordinates that are stored in a mysql table. I'm fairly new to php...I use perl and mysql together frequently. I started with the basics and just ensured php was connecting with my database. Then, I attempted to draw simple points onto the google map using some javascript and php. But I can't go from there to the polylines. Also, I can't seem to get any error reports, so I'm not sure where the errors are....probably everywhere

    Here's the code that works for the points:
    Code:
    <html>
    <head>
    <title>Who locations in London</title>
    <script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAkc_saF95f9yN260PF4w0pRQaLQNZjCm4hXvKpkQzsIUyzShiFxTy8Mzmg1zhI0wwmmTefQckSMO7aQ" 
    
    type="text/javascript"></script>
    </head>
    <body>
    <p><strong>Who-locations in London</strong></p>
    <div id="map" style="width: 800px; height: 600px"></div> 
    
    <script type="text/javascript">
    //<![CDATA[
    
    var map = new GMap2(document.getElementById("map"));
    map.addControl(new GLargeMapControl());
    map.addControl(new GMapTypeControl());
    map.addControl(new GScaleControl());
    map.setCenter(new GLatLng(32.512161, -122.14110), 5, G_NORMAL_MAP);
    
    // Creates a marker whose info window displays the given number
    function createMarker(point, number)
    {
    var marker = new GMarker(point);
    // Show this markers index in the info window when it is clicked
    var html = number;
    GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml(html);});
    return marker;
    };
    
    <?php
    error_reporting(E_ALL);
    
    $link = mysql_connect("___", "____", "pword") or die ("Could not connect: " . mysql_error());
    mysql_selectdb("test",$link) or die ("Can\'t use dbmapserver : " . mysql_error());
    
    $result = mysql_query("SELECT * FROM cwa_location",$link);
    if (!$result)
    {
    echo "no results ";
    }
    while($row = mysql_fetch_array($result))
    {
    echo "var point = new GLatLng(" . $row['lat1'] . "," . $row['lon1'] . ");\n";
    echo "var marker = createMarker(point, '" . addslashes($row['description']) . "');\n";
    echo "map.addOverlay(marker);\n";
    echo "\n";
    }
    
    
    mysql_close($link);
    ?>
    
    
    </script>
    
    </body>
    </html>
    And here's what I've tried so far with the polylines.
    Code:
    <html>
    <head>
    <title>Who locations in London</title>
    <script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAkc_saF95f9yN260PF4w0pRQaLQNZjCm4hXvKpkQzsIUyzShiFxTy8Mzmg1zhI0wwmmTefQckSMO7aQ" 
    
    type="text/javascript"></script>
    </head>
    <body>
    <p><strong>Who-locations in London</strong></p>
    <div id="map" style="width: 800px; height: 600px"></div> 
    
    <script type="text/javascript">
    //<![CDATA[
    
    var map = new GMap2(document.getElementById("map"));
    map.addControl(new GLargeMapControl());
    map.addControl(new GMapTypeControl());
    map.addControl(new GScaleControl());
    map.setCenter(new GLatLng(32.512161, -122.14110), 5, G_NORMAL_MAP);
    
    
    
    
    <?php
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    error_reporting(E_ALL); 
    error_reporting(E_ALL|E_STRICT); 
    
    
    
    $link = mysql_connect("____", "____", "pword") or die ("Could not connect: " . mysql_error());
    mysql_selectdb("test",$link) or die ("Can\'t use dbmapserver : " . mysql_error());
    
    $result = mysql_query("SELECT * FROM cwa_location",$link);
    if (!$result)
    {
    echo "no results ";
    }
    
    $firstlat=mysql_result($result,"lat1");
    $firstlon=mysql_result($result,"lon1");
    $secondlat=mysql_result($result,"lat2");
    $secondlon=mysql_result($result,"lon2");
    
    echo "var polyline = new GPolyline([  new GLatLng($firstlat, $firstlon),  new GLatLng($secondlat, $secondlon)], "#ff0000", 4)";
    echo "map.addOverlay(polyline)";
    
    echo "\n";
    
    
    
    
    
    
    mysql_close($link);
    ?>
    
    
    </script>
    
    </body>
    </html>
    Does anyone have experience with this that might tell me where I'm going wrong? I've seen some examples posted on the web, but none seem to be as simple as what I'm trying to do. Thanks for any help!
    Shad
    Last edited by shadkeene; 01-01-2008 at 01:26 AM.

  • #2
    Regular Coder
    Join Date
    May 2007
    Posts
    162
    Thanks
    13
    Thanked 0 Times in 0 Posts

    solved

    I found out the easiest way to do this is just to pass the php variables to javascript and then display the map using javascript, outside the php code...a link that shows how is here:http://p2p.wrox.com/topic.asp?TOPIC_ID=12125

    I couldn't display the google map using echo statements in php, though I'm sure that its possible.
    Shad


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •