Visualizzazione dei risultati da 1 a 6 su 6
  1. #1

    Google maps aggiunta makers da php

    Ciao a tutti sono nuovo ed avrei bisogno di una cortesia.
    In giro ho trovato questo codice che mi permette di inserire su google maps i maker
    Codice PHP:
    <?php$conn mysql_connect("localhost""xxx""xxx") or die(mysql_error());mysql_select_db("mattina") or die(mysql_error());
    ?>    <html>    <head>        <meta http-equiv="content-type" content="text/html; charset=utf-8"/>        <title>SctWeb Mappa</title>        <style type="text/css">            body { font: normal 15pt Helvetica, Arial; }            #map { width: 850px; height: 700px; border: 5px; padding: 5px; }        </style>        <script src="http://maps.google.com/maps/api/js?key=mia_chiave_inserita_&sensor=false" type="text/javascript"></script>        <script type="text/javascript">        var icon = new google.maps.MarkerImage("http://maps.google.com/mapfiles/ms/micons/yellow.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 cognome, nome, geo, lat, lng FROM moto")or die(mysql_error());while($row mysql_fetch_array($query)){$cognome$row['cognome'];$nome$row['nome'];  $lat $row['lat'];  $lng $row['lng'];  $desc $row['geo'];  echo("addMarker($lat$lng, '$cognome.$nome');\n");   }   ?> center = bounds.getCenter();     map.fitBounds(bounds);
         }     </script>     </head>     <body onload="initMap()" style="margin:5px; border:5px; padding:5px;">     <div id="map"></div>     </body>     </html>
    Il codice funziona correttamente cioè mi fa vedere i makers sulla mappa ma se cambio solo la tabella nella query non mi fa vedere più la mappa.
    Codice PHP:
    <?php$conn mysql_connect("localhost""xxx""xxx") or die(mysql_error());mysql_select_db("mattinale") or die(mysql_error());?>    <html>    <head>        <meta http-equiv="content-type" content="text/html; charset=utf-8"/>        <title>SctWeb Mappa</title>        <style type="text/css">            body { font: normal 15pt Helvetica, Arial; }            #map { width: 850px; height: 700px; border: 5px; padding: 5px; }        </style>        <script src="http://maps.google.com/maps/api/js?key=mia_chiave_inserita&sensor=false" type="text/javascript"></script>        <script type="text/javascript">        var icon = new google.maps.MarkerImage("http://maps.google.com/mapfiles/ms/micons/yellow.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 cognome, nome, geo, lat, lng FROM veicoli")or die(mysql_error());while($row mysql_fetch_array($query)){$cognome$row['cognome'];$nome$row['nome'];  $lat $row['lat'];  $lng $row['lng'];  $desc $row['geo'];  echo("addMarker($lat$lng, '$cognome.$nome');\n");   }   ?> center = bounds.getCenter();     map.fitBounds(bounds);
         }     </script>     </head>     <body onload="initMap()" style="margin:5px; border:5px; padding:5px;">     <div id="map"></div>     </body>     </html>
    Da premettere che le tabella mysql sono identiche.
    Come mai secondo voi?

    Grazie
    http://www.angelogalantino.com

  2. #2
    Moderatore di Programmazione L'avatar di LeleFT
    Registrato dal
    Jun 2003
    Messaggi
    17,320
    Che c'entra Java con PHP?

    Sposto nel forum PHP.


    Ciao.
    "Perchè spendere anche solo 5 dollari per un S.O., quando posso averne uno gratis e spendere quei 5 dollari per 5 bottiglie di birra?" [Jon "maddog" Hall]
    Fatti non foste a viver come bruti, ma per seguir virtute e canoscenza

  3. #3
    sei sicuro che le tabelle hanno gi stessi campi?
    se no non si spiega.
    (anche se il codice non è molto leggibile....).

  4. #4
    questo è il codice diciamo funzionante
    <?php$conn = mysql_connect("localhost", "xxxx", "xxxx") or die(mysql_error());
    mysql_select_db("mattina") or die(mysql_error());


    ?>
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title> Mappa</title>
    <style type="text/css">
    body { font: normal 15pt Helvetica, Arial; }
    #map { width: 850px; height: 700px; border: 5px; padding: 5px; }
    </style>
    <script src="http://maps.google.com/maps/api/js?key=_____________&sensor=false" type="text/javascript"></script>
    <script type="text/javascript">
    var icon = new google.maps.MarkerImage("http://maps.google.com/mapfiles/ms/micons/yellow.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 cognome, nome, geo, lat, lng FROM moto")or die(mysql_error());
    while($row = mysql_fetch_array($query))
    {
    $cognome= $row['cognome'];
    $nome= $row['nome'];
    $lat = $row['lat'];
    $lng = $row['lng'];
    $desc = $row['geo'];
    echo("addMarker($lat, $lng, '$cognome.$nome');\n");

    }

    ?>
    center = bounds.getCenter();
    map.fitBounds(bounds);


    }
    </script>
    </head>
    <body onload="initMap()" style="margin:5px; border:5px; padding:5px;"></body>
    </html>
    questo è quello non funzionante
    <?php
    $conn = mysql_connect("localhost", "xxxx", "xxxx") or die(mysql_error());
    mysql_select_db("mattinale") or die(mysql_error());


    ?>
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title> Mappa</title>
    <style type="text/css">
    body { font: normal 15pt Helvetica, Arial; }
    #map { width: 850px; height: 700px; border: 5px; padding: 5px; }
    </style>
    <script src="http://maps.google.com/maps/api/js?key=________________&sensor=false" type="text/javascript"></script>
    <script type="text/javascript">
    var icon = new google.maps.MarkerImage("http://maps.google.com/mapfiles/ms/micons/yellow.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 veicoli")or die(mysql_error());
    while($row = mysql_fetch_array($query))
    {
    $cognome= $row['cognome'];
    $nome= $row['nome'];
    $lat = $row['lat'];
    $lng = $row['lng'];
    $desc = $row['luogo_furto'];
    echo("addMarker($lat, $lng, '$cognome.$nome');\n");
    }

    ?>
    center = bounds.getCenter();
    map.fitBounds(bounds);


    }
    </script>
    </head>
    <body onload="initMap()" style="margin:5px; border:5px; padding:5px;"></body>
    </html>

    I dati vengono comunque cercati solo in lat e lng.

    schermata6.jpg schermata7.jpg
    Ultima modifica di benexxx; 15-07-2015 a 15:26
    http://www.angelogalantino.com

  5. #5
    ho dato un'occhiata veloce al codice.
    se in effetti cambia solo la query, allora il problema è nel db.
    però dalle immagini non si vedono le strutture delle tabelle (o almeno io non ha la vista bionica).

  6. #6
    http://www.angelogalantino.com

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.