[問題] 關於google map api v3

看板Ajax作者 (Froyo)時間12年前 (2012/03/30 13:55), 編輯推噓1(103)
留言4則, 2人參與, 最新討論串1/1
最近想要實作 計算兩地只距離function, 不過根據官方的function, 似乎無法使用同步(Sync)方式運行, 請問各位是否有其他方案可以解決呢?@@ function cal(add1,add2){ var mygc = new google.maps.Geocoder(); var locationOrigem; var locationDestino; var latOrigem = 0; var longOrigem = 0; var latDestino = 0; var longDestino = 0; mygc.geocode({'address' : add1}, function(results, status){ locationOrigem = results[0].geometry.location; latOrigem = results[0].geometry.location.lat(); longOrigem = results[0].geometry.location.lng(); mygc.geocode({'address' : add2}, function(results, status){ locationDestino = results[0].geometry.location; latDestino = results[0].geometry.location.lat(); longDestino = results[0].geometry.location.lng(); console.log(locationOrigem); console.log(locationDestino); r=google.maps.geometry.spherical.computeDistanceBetween(locationOrigem, locationDestino); //距離結果 }); }); } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.116.96.69

03/30 14:12, , 1F
直線距離?
03/30 14:12, 1F

03/30 14:21, , 2F
我想要輸入兩地地址 輸出距離
03/30 14:21, 2F

03/30 14:30, , 3F
後來發現好像要用JSON API就能解決了= =
03/30 14:30, 3F

03/30 15:03, , 4F
恩~自己搞定了=..= 用JSON解決!!!
03/30 15:03, 4F
文章代碼(AID): #1FTKgrnj (Ajax)