Javascript-форум (https://javascript.ru/forum/)
-   Общие вопросы Javascript (https://javascript.ru/forum/misc/)
-   -   Как расчитаться дистанцию с Google API (https://javascript.ru/forum/misc/20744-kak-raschitatsya-distanciyu-s-google-api.html)

EventPromo 15.08.2011 22:03

Как расчитаться дистанцию с Google API
 
How to calculate driving distance with Google Maps API
http://briancray.com/2009/06/23/calc...ogle-maps-api/

все выполнил как у них фактически. только у меня вместо сабмита, обработчик события фокус аут:

$(document).ready(function () {
	initialize();
	$("#shiperCityBox").focusout(function () { showLocation(); return false; });
});

function initialize() {
	geocoder = new GClientGeocoder();
	gDir = new GDirections();
	GEvent.addListener(gDir, "load", function () {
		var drivingDistanceMiles = gDir.getDistance().meters / 1609.344;
		document.getElementById('carrierMilesBox').value = drivingDistanceMiles.toFixed();
	});
}

function showLocation() {
	geocoder.getLocations(document.getElementById("shiperCityBox").value, function (response) {
		if (!response || response.Status.code != 200) {
			alert("Sorry, we were unable to geocode the first address");
		}
		else {
			location1 = { lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address };
			geocoder.getLocations(document.getElementById("consigneeCityBox").value, function (response) {
				if (!response || response.Status.code != 200) {
					alert("Sorry, we were unable to geocode the second address");
				}
				else {
					location2 = { lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address };
					gDir.load('from: ' + location1.address + ' to: ' + location2.address);
				}
			});
		}
	});


но ничего не работает, всегда Response - response is not defined. В чем проблема? кто может подсказать?

если просто взять повесить как обработчик на кнопку:
<asp:Button ID="btnBottomSave" Text="Save" runat="server" OnClientClick="showLocation(); return false;" OnClick="Save_Click" CssClass="Button" />

все работает хорошо, но мне надо чтобы выполнялся еще серверный код, а при такой ситуации он не выполняется... что нужно делать?

devote 15.08.2011 22:19

может просто из формы гугл что-то еще берет помимо обычного нажатия кнопки. Это третья версия API я так понимаю? просто с третей не работал, небыло возможности... но со второй работал... хотя третья отличается значительно от второй.

EventPromo 15.08.2011 22:23

да вроде не берет ничего!

EventPromo 16.08.2011 15:16

косяк был в том что у меня элементы были в update panel. вопрос был решен.

Sys.WebForms.PageRequestManager.getInstance().add_ endRequest(RequestHandler);

function RequestHandler() {
initialize();
$("#shiperCityBox").focusout(function () { showLocation(); });
$("#consigneeCityBox").focusout(function () { showLocation(); });
$("#shiperAddressBox").focusout(function () { showLocation(); });
$("#consigneeAddressBox").focusout(function () { showLocation(); });
}


Часовой пояс GMT +3, время: 09:56.