我正在處理一些我並不瞭解的JavaScript,以便對我在Parse.com上的類中的對象上存儲的地址進行地理編碼。通過Cloud Code,我有一個PFObect的屬性,我需要將其傳遞給地理編碼器,然後解析生成的經緯度返回值,然後最終將其保存爲同一個PFObject的屬性。通過Parse Cloud使用Google Maps API進行地理編碼代碼
我花了大量時間尋找解決方案,而且大多數建議似乎都是使用Google Maps JavaScript API v3而不是HTTP請求。
這裏是我的代碼:
Parse.Cloud.afterSave ('incidentDetails', function(request, status) {
var address = request.object.get("address1");
var geocoder;
function initialize() {
geocoder = new google.maps.Geocoder();
codeAddress();
}
function codeAddress() {
console.log("test");
geocoder.geocode({ 'address':address}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var latLng = results[0].geometry.location;
request.object.set("latLng", latLng);
} else {
alert('Geocode was not successful for the following reasons: ' + status);
}
});
}
initialize();
});
我希望有人與此有些經驗可以指導我在正確的方向。上述代碼在Parse Cloud Code中正確部署,但是我不確定它是否被實際調用,因爲日誌或錯誤控制檯中沒有任何內容。我覺得我錯過了一些根本性的東西 - 我感謝任何幫助或建議。
如果您在參數中討論YourKey:{ address:address, key:YourKey },則它是Google地理編碼API密鑰而不是解析應用密鑰。 – 2015-02-09 03:16:34