小编use*_*497的帖子

javascript中两个位置之间的距离

有人可以帮我解决这个代码片段出了什么问题吗?我最终的目标是使用google javascript API查找距离两个位置.我已经使用geocomplete jquery函数进行地址自动完成.点击搜索没有任何事情发生.我只是一个初学者请帮忙

<!DOCTYPE html>
<html>
  <head>
    <title>Distance between Two Places</title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="styles.css" />
     <script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAA7j_Q-rshuWkc8HyFI4V2HxQYPm-xtd00hTQOC0OXpAMO40FHAxT29dNBGfxqMPq5zwdeiDSHEPL89A" type="text/javascript"></script>
     <script type="text/javascript">

    var geocoder, location1, location2;

    function initialize() {
        geocoder = new GClientGeocoder();
    }

    function showLocation() {
        geocoder.getLocations(document.forms[0].address1.value, function (response) {
            if (!response || response.Status.code != 200)
            {
                alert("Sorry, we were unable to geocode the first address");
            }
            else
            {
                location1 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
                geocoder.getLocations(document.forms[0].address2.value, function (response) {
                    if (!response || response.Status.code != 200) …
Run Code Online (Sandbox Code Playgroud)

javascript jquery google-maps google-maps-api-3

2
推荐指数
2
解决办法
1万
查看次数