我正在尝试将Google Map添加到房地产网站,并将搜索结果显示为标记。
我尝试使用别人的脚本,但是没有运气。该地图从不显示,并且Javascript控制台告诉我initmap不是函数。
这是我拥有的代码,希望您能找到可以解决问题的代码!
<script type="text/javascript">
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
zoom: 8
});
var locations = [
@foreach ($results as $result)
['{!! $result->CleanStreet !!}', {!! $result->GoogleLat !!}, {!! $result->GoogleLong !!}],
@endforeach
];
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
</script>
一旦PHP处理了这个,HTML / Javascript结果就是以下代码:
<script type="text/javascript">
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
zoom: 8
});
var locations = [
['8660 Cedar Hammock Circle Unit 322', 26.140668, -81.698089],
['9101 West Ridge Court', 26.541425, -81.804501],
['10290 Heritage Bay Boulevard Unit 3216', 26.292545, -81.662003],
['9315 La Playa Court Unit 1724', 26.330256, -81.789812],
['249 Santa Barbara Boulevard', 26.645446, -81.97389],
['113 Bristol Lane Unit C-7', 26.131782, -81.744884],
['9107 Capistrano Street South Unit 7807', 26.073019, -81.692355],
['529 Mardel Dr Unit 305', 26.160333, -81.725621],
['6810 Beach Resort Dr Unit 2408', 26.062845, -81.694866],
['5096 Beckton Rd', 26.324608, -81.434582],
['3405 Laurel Greens Lane South Unit 103', 26.288141, -81.740695],
['3001 Sandpiper Bay Circle Unit B306', 26.126653, -81.781391],
['7970 Mahogany Run Lane East Unit 212', 26.085334, -81.700158],
['6040 Huntington Woods Dr Unit 138-3', 26.109974, -81.716066],
['18011 Bonita National Boulevard Unit 927', 26.323263, -81.661097],
['11134 Oxbridge Way', 26.581582, -81.78171],
['511 Lake Louise Circle Unit 103', 26.303775, -81.817587],
['1926 Morning Sun Lane Unit C-16', 26.261981, -81.706231],
['7950 Mahogany Run Lane Unit 426', 26.085257, -81.699656],
['4970 Deerfield Way Unit F-204', 26.273836, -81.750093],
['2135 Pigeon Plum Way', 26.755909, -81.917998],
['9852 Luna Circle Unit B-104', 26.260865, -81.768194],
['45 High Point Circle South Unit 107', 26.185164, -81.794543],
['6084 Huntington Woods Dr', 26.111284, -81.717452],
['23741 Eddystone Road Unit 3202', 26.394524, -81.778416],
['27605 Pinecrest Lane', 26.337074, -81.752178],
['7768 Jewel Lane Unit 101', 26.242458, -81.776317],
['8394 San Carlos Boulevard', 26.470159, -81.808654],
['5440 Worthington Lane Unit 103', 26.278617, -81.752315],
['28424 Altessa Way Unit 202', 26.326411, -81.753116],
];
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
</script>