问题
Can anyone tell me the Google map generated Java Script my code is not working. This java script dynamically located items for different dynamically category levels display the Google map Icons in different colours. I am using MCV 5 and C#. I have attached my Java Script code.
function initialize() {
var myLatLng = new google.maps.LatLng(-34.397, 150.644);
var options =
{
zoom: 6,
center: new google.maps.LatLng(-34.397, 150.644),
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: true,
mapTypeControlOptions:
{
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU,
poistion: google.maps.ControlPosition.TOP_RIGHT,
mapTypeIds: [google.maps.MapTypeId.ROADMAP,
google.maps.MapTypeId.TERRAIN,
google.maps.MapTypeId.HYBRID,
google.maps.MapTypeId.SATELLITE]
},
navigationControl: true,
navigationControlOptions:
{
style: google.maps.NavigationControlStyle.ZOOM_PAN
},
scaleControl: true,
disableDoubleClickZoom: true,
draggable: true,
streetViewControl: true,
draggableCursor: 'move'
};
@foreach (var item in Model)
{
<text>
var map = new google.maps.Map(document.getElementById("map"), options);
var iconUrl = "";
var list = @Html.Raw(Json.Encode(ViewBag.CourierList));
for (var i = 0; i < list.length-1; i++) {
var model = list[i];
addMarker(model.IconUrl, new google.maps.LatLng(@item.Latitude,@item.Longitude));
// addMarker(returnIcon(model.Category), new google.maps.LatLng(@item.Latitude,@item.Longitude));
}
iconUrl = "http://maps.google.com/mapfiles/ms/icons/" + icon + ".png";
function addMarker(iconUrl, myLatLng) {
var marker = new google.maps.Marker({
position: myLatLng,
icon: iconUrl,
map: map,
title: 'Click me',
animation: google.maps.Animation.DROP,
draggable: false
});
}
function returnIcon(category){
var iconUrl = 'default.ico';
if(category == 'AAA')
iconUrl = 'abc.ico';
icon = "blue";
if(category == 'BBB')
iconUrl = 'red.ico';
return iconUrl;
}
var infoWindow = new google.maps.InfoWindow();
var contentString =
'<div id="content" style="width:200px; background-color:yellow;">' +
'Ref: @item.Map_Ref' +'<br>' +
'Name: @item.CustomerName' +'<br>' +
'Pay by: @item.Pay_By' +'<br>' +
'Order ID: @item.OrderId <br>' +
'Tel: @item.CustomerPhone' +'<br>' +
'Price:<b>$ @item.Total_Price </b><br>' +
'</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
google.maps.event.addListener(marker, 'click', (function(marker, contentString) {
return function() {
infowindow.setContent(contentString);
infowindow.open(map, marker);
}
})(marker, contentString));
//return marker;
</text>
}
google.maps.event.addDomListener(window, 'load', initialize);
}
来源:https://stackoverflow.com/questions/27440324/google-map-icons-in-different-colours-java-script-my-code-is-not-working