0
我有一个位置字段的用户提交表单。我想调用Google地理编码API并获取位置的纬度和经度以确保位置存在,然后将所有三个数据发送到数据库。如何在Meteor应用程序表单提交中实现地理编码?
geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': location}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
alert(results[0].geometry.location);
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
我可以找得到这个代码,以提醒正确的坐标的唯一地方是在我的收藏posts.js文件,但它也导致了服务器错误:
Exception while invoking method 'post' ReferenceError: google is not defined
您是否在您的'
..'部分引用了google apis? – Akshat是的,坐标是进来的。我只是不知道我应该把地理编码放在我的文件中,以及如何防止服务器错误。 –
哦,我明白了,你正在服务器上运行它?您需要使用某种服务器端插件,例如(npm)-https://npmjs.org/package/geocoder,因为Google地址解析器API仅适用于客户端 – Akshat