它工作,但当我想在母版页中使用这些代码时,我遇到了问题。这个问题是关于坐标。它正在寻找工作,但不要带我坐标。
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?v=3.1&sensor=false&language=tr"></script>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<link href="css/yonetici.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
var geocoder = new google.maps.Geocoder();
function geocodePosition(pos) {
geocoder.geocode({
latLng: pos
}, function (responses) {
if (responses && responses.length > 0) {
updateMarkerAddress(responses[0].formatted_address);
} else {
updateMarkerAddress('Cannot determine address at this location.');
}
});
}
function updateMarkerStatus(str) {
document.getElementById('markerStatus').innerHTML = str;
}
function updateMarkerPosition(latLng) {
document.getElementById('info').innerHTML = [
latLng.lat(),
latLng.lng()
].join(', ');
}
function updateMarkerAddress(str) {
document.getElementById('address').innerHTML = str;
}
function initialize() {
var latLng = new google.maps.LatLng(39.909450, 34.849715);
var map = new google.maps.Map(document.getElementById('mapCanvas'), {
zoom: 8,
center: latLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var marker = new google.maps.Marker({
position: latLng,
title: 'Point A',
map: map,
draggable: true
});
// Update current position info.
updateMarkerPosition(latLng);
geocodePosition(latLng);
// Add dragging event listeners.
google.maps.event.addListener(marker, 'dragstart', function () {
updateMarkerAddress('Sürükleniyor...');
});
document.forms[0].txtLat.value = 40.775146501143766;
document.forms[0].txtLng.value = 30.384921661376946;
google.maps.event.addListener(marker, "drag", function () {
var latlng = marker.getPosition();
document.forms[0].txtLat.value = latlng.lat();
document.forms[0].txtLng.value = latlng.lng();
});
google.maps.event.addListener(marker, 'dragend', function () {
geocodePosition(marker.getPosition());
});
}
// Onload handler to fire off the app.
</script>
<script type="text/javascript">
$(function () {
var menu_ul = $('.menu > li > ul'),
menu_a = $('.menu > li > a');
menu_ul.hide();
menu_a.click(function (e) {
e.preventDefault();
if (!$(this).hasClass('active')) {
menu_a.removeClass('active');
menu_ul.filter(':visible').slideUp('normal');
$(this).addClass('active').next().stop(true, true).slideDown('normal');
} else {
$(this).removeClass('active');
$(this).next().stop(true, true).slideUp('normal');
}
});
});
</script>
</head>
<body onload="initialize()">
<form id="form1" runat="server">
<div class="ad_googlemaps_area" >
<div id="mapCanvas"></div>
<div id="infoPanel">
<div id="info" style="display:none;" ></div>
<b>Tahmini Adres:</b>
<div id="address" ></div>
<b>Enlem</b>
<asp:TextBox ID="txtLat" runat="server"></asp:TextBox>
<b>Boylam:</b>
<asp:TextBox ID="txtLng" runat="server"></asp:TextBox>
</div>
</div>
</form>
</body>
从你的body元素和javascript中删除onload属性和初始化方法,而不是将你的代码放在pageLoad方法中,如下所示:
function pageLoad(sender, args) { //use this method to load your map var geocoder = new google.maps.Geocoder(); var latLng = new google.maps.LatLng(39.909450, 34.849715); var map = new google.maps.Map(document.getElementById('mapCanvas'), { zoom: 8, center: latLng, mapTypeId: google.maps.MapTypeId.ROADMAP }); var marker = new google.maps.Marker({ position: latLng, title: 'Point A', map: map, draggable: true }); // Update current position info. updateMarkerPosition(latLng); geocodePosition(latLng); // Add dragging event listeners. google.maps.event.addListener(marker, 'dragstart', function () { updateMarkerAddress('Sürükleniyor...'); }); document.forms[0].txtLat.value = 40.775146501143766; document.forms[0].txtLng.value = 30.384921661376946; google.maps.event.addListener(marker, "drag", function () { var latlng = marker.getPosition(); document.forms[0].txtLat.value = latlng.lat(); document.forms[0].txtLng.value = latlng.lng(); }); google.maps.event.addListener(marker, 'dragend', function () { geocodePosition(marker.getPosition()); }); function geocodePosition(pos) { geocoder.geocode({ latLng: pos }, function (responses) { if (responses && responses.length > 0) { updateMarkerAddress(responses[0].formatted_address); } else { updateMarkerAddress('Cannot determine address at this location.'); } }); } function updateMarkerStatus(str) { document.getElementById('markerStatus').innerHTML = str; } function updateMarkerPosition(latLng) { document.getElementById('info').innerHTML = [ latLng.lat(), latLng.lng() ].join(', '); } function updateMarkerAddress(str) { document.getElementById('address').innerHTML = str; } // Onload handler to fire off the app. }
如果您仍然无法加载地图,请与我们联系。
我尝试但同样的问题。
function pageLoad(sender, args) { //use this method to load your map
var geocoder = new google.maps.Geocoder();
var latLng = new google.maps.LatLng(39.909450, 34.849715);
var map = new google.maps.Map(document.getElementById('mapCanvas'), {
zoom: 8,
center: latLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var marker = new google.maps.Marker({
position: latLng,
title: 'Point A',
map: map,
draggable: true
});
// Update current position info.
updateMarkerPosition(latLng);
geocodePosition(latLng);
// Add dragging event listeners.
google.maps.event.addListener(marker, 'dragstart', function () {
updateMarkerAddre**strong text**ss('Sürükleniyor...');
});
到目前为止没有问题
问题从这里开始
document.forms[0].txtLat.value = 40.775146501143766;
document.forms[0].txtLng.value = 30.384921661376946;
google.maps.event.addListener(marker, "drag", function () {
var latlng = marker.getPosition();
document.forms[0].txtLat.value = latlng.lat();
document.forms[0].txtLng.value = latlng.lng();
});
google.maps.event.addListener(marker, 'dragend', function () {
geocodePosition(marker.getPosition());
});
function geocodePosition(pos) {
geocoder.geocode({
latLng: pos
}, function (responses) {
if (responses && responses.length > 0) {
updateMarkerAddress(responses[0].formatted_address);
} else {
updateMarkerAddress('Cannot determine address at this location.');
}
});
}
function updateMarkerStatus(str) {
document.getElementById('markerStatus').innerHTML = str;
}
function updateMarkerPosition(latLng) {
document.getElementById('info').innerHTML = [
latLng.lat(),
latLng.lng()
].join(', ');
}
function updateMarkerAddress(str) {
document.getElementById('address').innerHTML = str;
}
// Onload handler to fire off the app.
}