Visualizzazione dei risultati da 1 a 3 su 3

Discussione: [google maps] Autozoom

  1. #1
    Utente di HTML.it L'avatar di Svipla
    Registrato dal
    Dec 2012
    Messaggi
    76

    [google maps] Autozoom

    Ciao a tutti
    sto inserendo diversi marker in una mappa e vorrei che lo zoom si adattasse ai marker inseriti.
    Come posso fare per impostare l'autozoom?
    Grazie mille

  2. #2
    Utente di HTML.it L'avatar di Svipla
    Registrato dal
    Dec 2012
    Messaggi
    76
    Risolto così:
    codice:
     var bounds = new google.maps.LatLngBounds();
            var infowindow = new google.maps.InfoWindow();
            function initializeMap() {
                var mapOptions = {               
                    mapTypeId: google.maps.MapTypeId.ROADMAP
                };
                map = new google.maps.Map(document.getElementById('map-container'), mapOptions);
                getMapData();
            }
    
            function getMapData() {
                var jsonStrutture = $.parseJSON(JSON.stringify(objStrutture));
    
                if (jsonStrutture.length > 0) {
                    $.each(jsonStrutture, function () {
                        addMarker(this);
                    });
    
                    //now fit the map to the newly inclusive bounds
                    map.fitBounds(bounds);
                }
            }
    
            function addMarker(objStruttura) {
                ...
    
                if (lat != null && lng != null) {
                    var marker = new google.maps.Marker({
                        position: new google.maps.LatLng(lat, lng),
                        map: map
                    });
    
                    //extend the bounds to include each marker's position
                    bounds.extend(marker.position);
    
                    if (img != '') {
                        image = '<img src="' + img + '" width="200" />';
                    }
                    var content = '<div class="col-sm-12 row box-mappa">' +
                                        '<h5><span class="titolo-mappa">' + struttura + '</span> ' + stelle + '</h5>' +
                                        image +
                                        '<h6>' + indirizzo + '</h6>' +
                                        '<div class="text-left box-prezzo">' +
                                            notti + ' ' + lgNotti + ' ' +
                                            (totale < scontato ? '<span class="scontato-mappa">&euro; ' + scontato + '</span> ' : '') +
                                            '<span class="prezzo-mappa">&euro; ' + totale + '</span>' +
                                        '</div>' +
                                        '<div class="pull-right margin-top10">' +
                                            '<a id="hlPrenota" class="prenotaEvent button-mappa pointer" data-code="' + codiceStruttura + '">' + lgPrenota + '</a>' +
                                        '</div>' +
                                    '</div>';
    
                    google.maps.event.addListener(marker, 'click', (function (marker, i) {
                        return function () {
                            infowindow.setContent(content);
                            infowindow.open(map, marker);
                        }
                    })(marker, i));
                }//end if            
            }
    Ultima modifica di ciro78; 23-05-2016 a 20:47 Motivo: tag code

  3. #3
    Moderatore di Javascript L'avatar di ciro78
    Registrato dal
    Sep 2000
    residenza
    Napoli
    Messaggi
    8,514
    ciao,
    la prossima volta metti il codice nel tag code
    Ciro Marotta - Programmatore JAVA - PHP
    Preferisco un fallimento alle mie condizioni che un successo alle condizioni altrui.


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.