【问题标题】:finding distance using google map api使用谷歌地图api查找距离
【发布时间】:2015-01-21 15:44:49
【问题描述】:

谁能帮帮我。

我正在尝试创建一个页面,用户可以在其中输入起始位置和结束位置,并在提交时显示显示路线和距离的地图。

在我的数据库中,我有价格为 pr 的运营商。公里。

现在我想显示起点或终点附近的运营商,同时计算路线的每个运营商价格。

我的问题是我不知道我可以访问距离并在计算中使用它,

我正在使用经典的 asp 并访问数据库

我在函数中得到这样的距离:

document.getElementById("afstand").innerHTML = response.routes[0].legs[0].distance.value;

有没有办法让我可以像在全局变量中一样保存该值?

【问题讨论】:

  • 你已经看过这个问题了吗? stackoverflow.com/q/3251609/3915817如果是,你会说你做不到哪一部分?
  • 是的,我已经看到了,但我的问题是我的距离没问题,我可以在页面上写成 innerhtml,但我想要的是掌握那个距离,这样我就可以使用它在我的 asp 中计算价格
  • 您需要使用 javascript 发送表单 POST 或通过查询字符串中的 GET 将其发送到页面。您还可以使用 AJAX 将其发送到页面,具体取决于您想要使用它做什么。但请记住,一旦 ASP 生成并发送了页面,就没有其他方法可以与之交互了。
  • 正如 Octopoid 所说,有多种方法可以做到这一点。因此,要稍微缩小您的问题范围,您需要选择一种适合您的解决方案的方式。 1) 将信息发送到您可以使用 post 或 get 处理的页面 2) 使用 AJAX 调用在页面内动态处理它 3) 遍历 Access 信息以将其添加到 JavaScript 数组并使用 JavaScript 过滤你需要什么

标签: google-maps asp-classic


【解决方案1】:

我倾向于使用 JavaScript 函数将信息发布到 Classic ASP 中的等待“服务”,类似这样...

/*
    AJAX extension to allow dynamic interaction between pages.
    This section initialises the variable used to store the XMLHTTP request object.
*/
var xmlhttp;
if (window.XMLHttpRequest) xmlhttp=new XMLHttpRequest();    // code for IE7+, Firefox, Chrome, Opera, Safari...
else xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");      // code for IE6, IE5

/*
    ajaxPage
        Posts a request to the scripted specified page.
    Parameters:
        postPage (string) - The page to be opened.
        paramList (string) - The list of parameters/values to be applied to the page.
    Usage:
        var targetBlock = document.getElementById("resultDiv");
        targetBlock.innerHTML = ajaxPage("resultsPage.asp","calcVal=545")
    Description:
        This routine uses the xmlhttp requesting tools within JavaScript to act as an intermediary between
        script and page.  Specify all paramters in the paramList by separating with an ampersand (&).
*/
function ajaxPage(postPage, paramList) {xmlhttp.open("POST",postPage,false);xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");xmlhttp.send(paramList);return xmlhttp.responseText;}

然后我会将来自 Google 地图计算的数据发布到我的服务器页面以执行计算。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-11
    • 2014-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多