Visualizzazione dei risultati da 1 a 2 su 2

Discussione: Mappa google

  1. #1
    Utente di HTML.it
    Registrato dal
    Feb 2013
    Messaggi
    4

    Mappa google

    Ciao a tutti,
    ho recuperato il codice per inserire una google maps nella mia pagina html.
    Tramite php, dovrei usare semplicemente come parametro il nome di una città e inviarlo allo script della mappa: è possibile avere delle coordinate solamente specificando un nome ad esempio Roma?

    Codice PHP:
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
        <
    script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true&language=it"></script>
        <script type="text/javascript">       function initialize() {   
           var latlng = new google.maps.LatLng(40.1100, 8.9100); // centro della mappa  
            var myLatlng = new google.maps.LatLng(39.7779729,8.7450475); // segnapunto 
             // definizione della mappa 
             var myOptions = {         
            zoom: 8,           
           center: latlng,  
           mapTypeId: google.maps.MapTypeId.HYBRID,
           mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.HORIZONTAL_BAR}    
          }          
    mymap = new google.maps.Map(document.getElementById("map"), myOptions); 
       // definizione segnapunto          var marker = new google.maps.Marker({  
               position: myLatlng,   
               map: mymap,          
               title:"titolo blablabla"   
           });      
     }    </script> 

  2. #2
    qui http://www.html.it/articoli/google-maps-v3-geocoding/ trovi una guida che te lo spiega, comunque devi fare così, crei una pagina chiamata per esempio mappa.php con il seguente codice
    Codice PHP:



    <html>
    <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Google Maps API v3: geocoding</title>
    <style type="text/css">
    html, body { margin:0; padding:0; width:100%; height:100%; }
    body { background:#FFFFFF; color:#000000; font-family:Arial, Helvetica, sans-serif; font-size:12px; line-height:150%; text-align:center;}
    #map { width:100%; height:95%; }
    input { width:250px; }
    #tooltip { padding:10px; text-align:left; }
    #tooltip p { padding:0; margin:0 0 5px 0; }
    </style>
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
    <script type="text/javascript">

    var createMap = function() {
        
        searchAddress();

           var address = document.getElementById("address").value;
        
        var geocoder = new google.maps.Geocoder();
        
        geocoder.geocode( {'address': address}, function(results,status) {
            if (status == google.maps.GeocoderStatus.OK) {
            
                var options = {
                      zoom: 12,
                      center: results[0].geometry.location,
                      mapTypeId: google.maps.MapTypeId.ROADMAP
                };    

                var map = new google.maps.Map(document.getElementById('map'), options);
        
                var marker = new google.maps.Marker(
                    {
                      position: results[0].geometry.location,
                      map: map,
                      title: 'Spoleto'
                    }
                );
        
                var tooltip = '<div id="tooltip">'+
                    '

    formatted_address:
    '+                
                       results[0].formatted_address+'</p>'+
                    '

    latLng:
    '+
                    results[0].geometry.location+'</p>'+            
                    '</div>';
        
                var infowindow = new google.maps.InfoWindow({
                    content: tooltip
                });
        
                google.maps.event.addListener(marker, 'click', function() {
                      infowindow.open(map,marker);
                });
                
              
            } else {
              alert("Problema nella ricerca dell'indirizzo: " + status);
            }
          });
        
    }

    var searchAddress = function(){
        document.getElementById("submit").onclick = function() {
            createMap();
        }
    }

    window.onload = createMap;
    </script>
    </head>
    <body>
    <div>
        <input id="address" type="hidden" value="<?php echo $_GET['city']; ?>"/>
        <input id="submit" type="hidden" value="trova indirizzo sulla mappa"/>
    </div>
    <div id="map"></div>
    </body>
    </html>
    se vuoi cercare la città Torino ad esempio usi questo link http://example.com/mappa.php?city=torino

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.