0

私が使用している Google マップ スクリプトは、スクリプト タグを使用して Google マップを宣言するのに問題なく機能しますが、非同期でロードしたいので、変更に問題があります。これは私が現在持っているものです:

//<![CDATA[ 
$(window).load(function(){
var locations = [
[
"850 Boylston Street",
"Chestnut Hill, MA 02467",
"42.326435",
"-71.149499"
],
[
"Subway Brookline Village",
"Green Line, D",
"42.33279",
"-71.11630"
],
[
"Shuttle Brookline Village",
"10 Brookline Place",
"42.33262",
"-71.116439"
],
[
"Subway Chestnut Hill",
"Green Line, B",
"42.338164",
"-71.153164"
],
[
"Subway Cleveland Circle",
"Green Line, C",
"42.336145",
"-71.149323"
],
[
"Subway Reservoir",
"Green Line, D",
"42.335132",
"-71.148762"
],
[
"Bus 51 Reservoir",
"Pick up from Subway",
"42.335021",
"-71.148988"
],
[
"Bus 51 Route 9",
"Drop off Route 9",
"42.326499",
"-71.142588"
], 


[
"75 Francis Street",
"Boston, MA 02115",
"42.33619",
"-71.10705"
],
[
"Shuttle Longwood",
"Shapiro Building",
"42.33603",
"-71.10779"
],
[
"Subway Longwood",
"Green Line, D",
"42.34113",
"-71.11044"
],
[
"Subway Brigham Circle",
"Green Line, E",
"42.33422",
"-71.10455"
],
[
"Parking Garage",
"70 Francis Street",
"42.33422",
"-71.10455"
],



[
"20 Patriots Place",
"Foxboro, MA 02035",
"42.09254",
"-71.26629"
]
];

gmarkers = [];

var map = new google.maps.Map(document.getElementById('map'), {
zoom: 16,
center: new google.maps.LatLng(42.326435, -71.149499),
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl:false
});

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


function createMarker(latlng, html) {
var marker = new google.maps.Marker({
    position: latlng,
    map: map
});

google.maps.event.addListener(marker, 'click', function() {
    infowindow.setContent(html);
    infowindow.open(map, marker);
});
return marker;
}

for (var i = 0; i < locations.length; i++) {
/*    alert("location:"+
      locations[i][0]+":"+locations[i][2]+","+locations[i][3]);
*/
gmarkers[locations[i][0]]=
createMarker(new google.maps.LatLng(locations[i][2], locations[i][3]), locations[i][0]     
+ "<br>" + locations[i][1]);
}

/*                                                    
$(function() {
$('#locations h3 a').each(function() { 
    $(this).on('click', function() { 
        google.maps.event.trigger(marker, 'click');    
    })    
  });    
});

*/
});//]]>  
4

2 に答える 2

1

2 つのオプションがあります

  1. ここで説明されているようにスクリプト タグを挿入します: https://developers.google.com/maps/documentation/javascript/tutorial#Loading_the_Maps_API

  2. AjaxLoader を使用します。

https://google-developers.appspot.com/loader/

次のように追加します。

<script type="text/javascript" src="http://www.google.com/jsapi"> </script>

ページの上部で、次を使用してマップをロードします。

google.load("maps","3.9", {"other_params":"sensor=false"});

HTH

于 2012-10-29T16:05:10.477 に答える
0
    <script type="text/javascript">
        var map;

        function initialize() {
            var mapOpt = {
                /* le coordinate di partenza si possono impostare dal db */
                center: new google.maps.LatLng(42, 12),
                zoom: 15,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            map = new google.maps.Map(document.getElementById("googleMap"), mapOpt);

        }

...要素「< div id="googleMap">」を参照するHTMLで

于 2015-01-29T18:54:56.497 に答える