小编Jen*_*zor的帖子

Google Maps API:与航点的总距离

我正在尝试计算其中包含单个航点的航线的总距离,但不知何故,我的代码仅返回到第一航点而不是总距离的距离.

这是我的代码:

function calcRoute(homebase,from,to,via){
var start = from;
var end = to;
var wypt = [ ];
wypt.push({
            location:via,
            stopover:true});

var request = {
    origin:start,
    destination:end,
    waypoints:wypt,     
    optimizeWaypoints: true,
    travelMode: google.maps.DirectionsTravelMode.DRIVING,
    unitSystem: google.maps.DirectionsUnitSystem.METRIC
};

directionsService.route(request, function(response, status) {
  if (status == google.maps.DirectionsStatus.OK) {
    directionsDisplay.setDirections(response);

    var distance = response.routes[0].legs[0].distance.text; 
    var time_taken = response.routes[0].legs[0].duration.text; 

    var calc_distance = response.routes[0].legs[0].distance.value; 
  }
});
}
Run Code Online (Sandbox Code Playgroud)

javascript google-maps

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

jQuery/Ajax请求被发送两次

我一遍又一遍地扫描我的代码,但我似乎无法找到问题所在.当我单击链接时#add-user-btn,文件actions.php被调用两次(因此PHP脚本执行两次).

这是脚本:我想它与ajax请求前面的javascript有关?

$(function () {
    $("#add-user-btn").click(function (e) {
        e.preventDefault();
        var email = $("#email").val();
        var name = $("#name").val();
        var action = "adduser";

        $.ajax({
            url: '../actions.php',
            type: 'POST',
            data: {
                action: action,
                email: email,
                name: name,
            },
            dataType: 'json',
            success: function (data) {
                $(".close-reveal-modal").click();
            }
        });
    });
});
Run Code Online (Sandbox Code Playgroud)

HTML:

<div id="adduser" class="reveal-modal">
 <h1>Add new user</h1>
 <p><label for="email">E-mail:</label> <input id="email" name="email" type="text" placeholder="name@example.com" /></p>
 <p><label for="name">Name:</label> <input id="name" name="name" type="text" placeholder="Adam Smith"/></p>
 <p><label for="password">Password:</label> <input id="password" name="password" type="password" placeholder="123456" …
Run Code Online (Sandbox Code Playgroud)

php ajax jquery json

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

PHP正则表达式替换字母或空格包围的值

我一直试图找出一段时间的解决方案,但没有找到一个可靠的工作方式.

我有一个字符串,其中每个换行符表示为零(0)

$string ="The quick brown fox0jumped over the lazy dog 0with 1308mm to spare.";
Run Code Online (Sandbox Code Playgroud)

我正在寻找一种方法,用html标签"br"替换不属于数字的每个0.

到目前为止,我得到的最接近的是:

preg_replace('/([a-zA-Z ])0([a-zA-Z ])/', '$1\<br\>$2', $string);
Run Code Online (Sandbox Code Playgroud)

php regex expression preg-replace

0
推荐指数
1
解决办法
139
查看次数

标签 统计

php ×2

ajax ×1

expression ×1

google-maps ×1

javascript ×1

jquery ×1

json ×1

preg-replace ×1

regex ×1