Added reverse geocoding for location save

pull/73/head
jonsowman 2010-08-11 11:19:46 +00:00
rodzic b75357834f
commit 46153c7bec
2 zmienionych plików z 31 dodań i 6 usunięć

Wyświetl plik

@ -125,13 +125,13 @@ var hlTimeout = 5000; // high latency
<form name="location_save_form" id="location_save_form">
<table name="req_table" id="req_table">
<tr>
<td>Latitude: </td><td><input type="text" name="req_lat" id="req_lat" size="10"></td>
<td>Latitude: </td><td><input type="text" name="req_lat" id="req_lat" size="15"></td>
</tr><tr>
<td>Longitude: </td><td><input type="text" name="req_lon" id="req_lon" size="10"></td>
<td>Longitude: </td><td><input type="text" name="req_lon" id="req_lon" size="15"></td>
</tr><tr>
<td>Altitude: </td><td><input type="text" name="req_alt" id="req_alt" size="10"></td>
<td>Altitude: </td><td><input type="text" name="req_alt" id="req_alt" size="15"></td>
</tr><tr>
<td>Site Name: </td><td><input type="text" name="req_name" id="req_name" size="10"></td>
<td>Site Name: </td><td><input type="text" name="req_name" id="req_name" size="15"></td>
</tr><tr>
<td></td><td><input type="button" value="Save" name="submit" id="req_sub_btn"></td>
</tr>

Wyświetl plik

@ -612,6 +612,10 @@ function setupEventHandlers() {
var req_name = $("#req_name").val();
var cookie_name = "cusf_predictor";
var locations_limit = 5;
var name_limit = 20;
// Check the length of the name
if ( req_name.length > name_limit ) req_name = req_name.substr(0, name_limit);
// Now let's init the cookie
$.Jookie.Initialise(cookie_name, 99999999);
@ -715,11 +719,15 @@ function setupEventHandlers() {
$("#location_save_local").fadeOut();
});
$("#req_open").click(function() {
$("#req_lat").val($("#lat").val());
$("#req_lon").val($("#lon").val());
var lat = $("#lat").val();
var lon = $("#lon").val();
$("#req_lat").val(lat);
$("#req_lon").val(lon);
$("#req_alt").val($("#initial_alt").val());
// this is bad, use a geocoder to guess it
$("#req_name").val("Unnamed");
appendDebug("Trying to reverse geo-code the launch point");
rvGeocode(lat, lon, "req_name");
$("#location_save").fadeIn();
});
$(".tipsyLink").tipsy({fade: true});
@ -728,6 +736,23 @@ function setupEventHandlers() {
});
}
function rvGeocode(lat, lon, fillField) {
var geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(parseFloat(lat), parseFloat(lon));
var coded = "Unnamed";
geocoder.geocode({'latLng': latlng}, function(results, status) {
if ( status == google.maps.GeocoderStatus.OK ) {
// Successfully got rv-geocode information
appendDebug("Got a good response from the geocode server");
coded = results[1].address_components[1].short_name;
} else {
appendDebug("The rv-geocode failed: " + status);
}
// Now write the value to the field
$("#"+fillField+"").val(coded);
});
}
function constructCookieLocationsTable(cookie_name) {
var t = "";
t += "<table border='0'>";