无论我试图找到问题,我都没有得到任何结果!这是我的JavaScript:
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCHe4JT9sg9GES0XnscAbKXQbS-G4ZCwLc"></script>
<script type="text/javascript">
var inside = $("#inside").val();
function mapaccesspopup() {
setTimeout(function () {
$('#MapAccessModal').modal('show');
}, 300);
};
$(function () {
$('#prt').on('click', function () {
$('#dvMap').css("display", "block");
$('#zxcv').css("display", "none");
$('#radar').css("display", "none");
$('#radar3').css("display", "none");
$('#firstcap').css("display", "none");
$('#secondcap').css("display", "none");
$('#iok').css("display", "none");
initMap();
var swee = document.getElementById("access").value;
if (swee == 'q') {
mapaccesspopup();
$('#access').val('w');
}
});
});
$(function () {
$('#prtt').on('click', function () {
$('#dvMap').css("display", "block");
$('#zxcv').css("display", "none");
$('#radar').css("display", "none");
$('#radar3').css("display", "none");
$('#firstcap').css("display", "none");
$('#secondcap').css("display", "none");
$('#iok').css("display", "none");
initMap();
var swee = document.getElementById("access").value;
if (swee=='q') {
mapaccesspopup();
$('#access').val('w');
}
});
});
function initMap() {
//read the parameter values you want to send to server
var searchItem = $("#SearchItem").val();
var jobs = $("#Jobs").val();
var subid = $("#bluee").val();
var map = new google.maps.Map(document.getElementById('dvMap'),
{
zoom: 8
});
var url = "@Url.Action("AsMapAjax", "My")";
navigator.geolocation.getCurrentPosition(function (p) {
var latlngg = new google.maps.LatLng(p.coords.latitude, p.coords.longitude);
var mapOptions = {
center: latlngg,
zoom: 12,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var infoWindow = new google.maps.InfoWindow();
var map = new google.maps.Map(document.getElementById("dvMap"), mapOptions);
//You re Here
var iconoMarca = "../../images/bnm.png";
mymarker = new google.maps.Marker({
animation: google.maps.Animation.DROP,
map: map,
icon: iconoMarca,
position: latlngg,
optimized: false,
title:"شما اینجا هستید"
});
var numberMarkerImg = {
url: '../../images/webresize2.png',
labelOrigin: new google.maps.Point(30, -6)
};
$.post(url, { SearchItem: searchItem, jobid: jobs, subid: subid }, function (res) {
if (res.success) {
var latLng;
$.each(res.responseText, function (i, item) {
latLng = new google.maps.LatLng(item.Lat, item.Lng);
var marker = new google.maps.Marker({
position: latLng,
map: map,
icon: numberMarkerImg,
label: {
text: item.Title,
color: 'Black',
fontFamily: 'IranSans',
fontSize: '17'
},
animation: google.maps.Animation.DROP
});
@*var link=@Html.Raw("@Html.ActionLink(item.WdTitle, "+"Poster"+", new { id = Replace.SpaceToDash(item.WdTitle) + "+"__" + "item.WdId })");*@
//nahveye ferestadane meghdar be action
@*'@Url.Action("Display", "Customer")?uname=' + firstname + '&name=' + username;*@
@*var wdLink = '@Url.Action("Poster", "My")?id=' + item.Title.split(" ").join("-") + '__' + item.Id;
(function (marker, item) {
google.maps.event.addListener(marker, "click", function (e) {
infoWindow.setContent(item.Preamble);
infoWindow.open(map, marker);
window.location.href = wdLink;
});
})*@
var wdLink = '@Url.Action("Poster", "My")?id=' + item.Title.split(" ").join("-") + '__' + item.Id;
var contentString = '<div id="content">' +
'<div id="siteNotice">' +
'</div>' +
'<div id="firstHeading">' + item.Title + '</div>' +
'<div id="bodyContent">' +
'<p><b>' + item.Preamble + '</b></p>' +
'<p><h4> <a href="'+ wdLink+'">' +
'اطلاعات بیشتر</a></h4> ' +
'</p>' +
'</div>' +
'</div>';
},];
var sourceLocation = { lat: p.coords.latitude, lng: p.coords.longitude };
var destinationLocations =
[{ lat: item.Lat, lng: item.Lng }];
var directionsService;
var directionsDisplay;
directionsService = new google.maps.DirectionsService();
directionsDisplay = new google.maps.DirectionsRenderer({
map: map,
markerOptions: {
visible: false
}
});
function markerClicked(destinationLocation) {
var directionsRequest = {
origin: sourceLocation,
destination: destinationLocation,
travelMode: 'DRIVING'
};
directionsService.route(directionsRequest, handleDirectionResults);
}
function handleDirectionResults(result, status) {
if (status === 'OK') {
directionsDisplay.setDirections(result);
} else {
console.log(status);
}
}
function createDestinationMarkers() {
destinationLocations.forEach(function(location, index) {
marker.addListener('click', function () {
markerClicked(location);
});
})
}
var infowindow = new google.maps.InfoWindow({
content: contentString
});
marker.addListener('click', function () {
infowindow.open(map, marker);
createDestinationMarkers()
//flightPath.setMap(map);
});
(marker, item);
////
$(document).ready(function () {
$(window).resize(function () {
google.maps.event.trigger(map, 'resize');
});
google.maps.event.trigger(map, 'resize');
});
});
map.setCenter(latlngg);
}
});
});
}
</script>
您可以visit this website查看此问题。