我使用谷歌地圖API3一些Laravel 4.2更改谷歌地圖標記的顏色取決於變種
我需要顏色取決於VAR地圖是從我的數據庫
來找上的標記舉例來說,如果未來的變種是Rent
的標誌應該是紅色的,如果它Sell
的標誌應該是綠色
這是我嘗試
<script type="text/javascript">
var locations = [
@foreach($bannerMapBin as $pin)
['<div style="width:300px;"><div style="float:left;margin-right:10px;height:92px;overflow:hidden;width:120px;"><a href="{{ URL::to('property-details/'.$pin->id) }}">@foreach($pin->propImages->slice(0, 1) as $image){{ HTML::image('images/propertyImages/'.$image->image, $pin->title, array('width'=>100, 'height'=>100)) }}@endforeach</a></div>{{ HTML::link('property-details/'.$pin->id, $pin->title) }} <br/> {{ $pin->propLocation->city }}</div>', {{ $pin->propLocation->lat }}, {{ $pin->propLocation->lng }}, 'type: Rent'],
@endforeach
];
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: new google.maps.LatLng(25.412392055138543, 51.188288833984416),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
var icons = {
Rent: {
icon: 'http://maps.google.com/mapfiles/ms/icons/green-dot.png'
},
Sell: {
icon: 'http://chart.googleapis.com/chart?chst=d_map_pin_letter&chld=%E2%80%A2%7CFF0000'
}
};
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
icon: icons[locations.type],
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>
一切工作正常,但不能給這些標記的每一個不同的顏色。
我也試試這個'type: Rent'
在我locations
末,並使其作爲VAR那裏,但預期
可以發佈'locations'數組的樣本嗎?內在元素不是我的對象。 –
請提供證明問題的[mcve]。 – geocodezip