【发布时间】:2011-08-12 13:28:44
【问题描述】:
大家好!我尝试使用 getLatLng() 对邮政/邮政编码列表进行地理编码,并将生成的点存储在数据库中,以便稍后放置在地图上。这是我到目前为止所得到的:
$(".geocodethis").click(function () {
var geocoder = new GClientGeocoder();
var postalCode = $(this).siblings(".postal").val();
var id = $(this).siblings(".id").val();
geocoder.getLatLng(postalCode, function (point) {
if (!point) {
alert(postalCode + " not found");
} else {
alert(point);
var serializedPoint = $.param(point);
//Geocode(id, point);
}
});
});
function Geocode(id, point) {
alert(point);
$.post("/Demographic/Geocode/" + id, point, function () {
alert("success?");
});
}
但是当我尝试序列化点对象或在$.post() 中使用它时,我的错误控制台中出现了this.lat is not a function
根据我的研究,我了解到geocoder.getLatLng() 是异步的,这会如何影响我正在尝试做的事情?我没有在循环中运行这段代码,我正在尝试使用匿名回调函数发布这一点。
如何保存point 中的信息以供日后使用?
更新
创建标记并尝试发布仍会导致错误控制台中出现this.lat is not a function。
$(".geocodethis").click(function () {
var geocoder = new GClientGeocoder();
var postalCode = $(this).siblings(".postal").val();
var id = $(this).siblings(".id").val();
geocoder.getLatLng(postalCode, function (point) {
if (!point) {
alert(postalCode + " not found");
} else {
alert(point);
var marker = new GMarker(point);
$.post("/Demographic/Geocode/" + id, marker, function () {
alert("success?");
});
}
});
});
** 另一个更新 **
我确实需要保存地理编码地址以备后用,即使我将纬度/经度值存储在数据库中并在准备将其放到地图上时重新制作标记。同样,序列化或发布 - 似乎以谷歌地图功能以外的任何方式使用该点会在我的错误日志中给出this.lat is not a function 异常。
我正在使用 asp.net mvc - 是否有任何框架可以让这更容易?我真的需要帮助。谢谢。
【问题讨论】:
标签: javascript jquery asp.net-mvc google-maps google-maps-api-2