Php 排序数组结果
我有一个数组,它是在ajax请求成功时生成的。从ajax请求获得的数组如下所示:Php 排序数组结果,php,jquery,arrays,ajax,sorting,Php,Jquery,Arrays,Ajax,Sorting,我有一个数组,它是在ajax请求成功时生成的。从ajax请求获得的数组如下所示: { "locationID": "9", "locationName": "Employee Residence", "locationLatitude": "34.47189", "locationLongitude": "-111.9896046999", "distance": 45456 } for ( var
{
"locationID": "9",
"locationName": "Employee Residence",
"locationLatitude": "34.47189",
"locationLongitude": "-111.9896046999",
"distance": 45456
}
for ( var i = 0; i < data.length; i++ ) {
var entry = data[i];
entry.distance = calculateDistance(entry.locationLongitude, entry.locationLatitude, LOCAL_LON, LOCAL_LAT);
}
数组:
将在此阵列上执行计算,该阵列提供位置列表及其与用户当前位置的距离。我想按距离对结果进行排序;我的代码如下:
Jquery:
当前结果:
期望的结果:
代码的“按距离排序”部分被注释掉,因为它不起作用。如有任何帮助以更正此代码或提供替代方法,我们将不胜感激。我是一个自学成才的业余网络开发者
谢谢
{
"locationID": "9",
"locationName": "Employee Residence",
"locationLatitude": "34.47189",
"locationLongitude": "-111.9896046999",
"distance": 45456
}
for ( var i = 0; i < data.length; i++ ) {
var entry = data[i];
entry.distance = calculateDistance(entry.locationLongitude, entry.locationLatitude, LOCAL_LON, LOCAL_LAT);
}
这是通过对给定数据进行如下迭代来完成的:
{
"locationID": "9",
"locationName": "Employee Residence",
"locationLatitude": "34.47189",
"locationLongitude": "-111.9896046999",
"distance": 45456
}
for ( var i = 0; i < data.length; i++ ) {
var entry = data[i];
entry.distance = calculateDistance(entry.locationLongitude, entry.locationLatitude, LOCAL_LON, LOCAL_LAT);
}
现在将有一个按距离排序的数组 {
"locationID": "9",
"locationName": "Employee Residence",
"locationLatitude": "34.47189",
"locationLongitude": "-111.9896046999",
"distance": 45456
}
for ( var i = 0; i < data.length; i++ ) {
var entry = data[i];
entry.distance = calculateDistance(entry.locationLongitude, entry.locationLatitude, LOCAL_LON, LOCAL_LAT);
}
这是通过对给定数据进行如下迭代来完成的:
{
"locationID": "9",
"locationName": "Employee Residence",
"locationLatitude": "34.47189",
"locationLongitude": "-111.9896046999",
"distance": 45456
}
for ( var i = 0; i < data.length; i++ ) {
var entry = data[i];
entry.distance = calculateDistance(entry.locationLongitude, entry.locationLatitude, LOCAL_LON, LOCAL_LAT);
}
现在将有一个按距离排序的数组 {
"locationID": "9",
"locationName": "Employee Residence",
"locationLatitude": "34.47189",
"locationLongitude": "-111.9896046999",
"distance": 45456
}
for ( var i = 0; i < data.length; i++ ) {
var entry = data[i];
entry.distance = calculateDistance(entry.locationLongitude, entry.locationLatitude, LOCAL_LON, LOCAL_LAT);
}
这是通过对给定数据进行如下迭代来完成的:
{
"locationID": "9",
"locationName": "Employee Residence",
"locationLatitude": "34.47189",
"locationLongitude": "-111.9896046999",
"distance": 45456
}
for ( var i = 0; i < data.length; i++ ) {
var entry = data[i];
entry.distance = calculateDistance(entry.locationLongitude, entry.locationLatitude, LOCAL_LON, LOCAL_LAT);
}
现在将有一个按距离排序的数组 {
"locationID": "9",
"locationName": "Employee Residence",
"locationLatitude": "34.47189",
"locationLongitude": "-111.9896046999",
"distance": 45456
}
for ( var i = 0; i < data.length; i++ ) {
var entry = data[i];
entry.distance = calculateDistance(entry.locationLongitude, entry.locationLatitude, LOCAL_LON, LOCAL_LAT);
}
这是通过对给定数据进行如下迭代来完成的:
{
"locationID": "9",
"locationName": "Employee Residence",
"locationLatitude": "34.47189",
"locationLongitude": "-111.9896046999",
"distance": 45456
}
for ( var i = 0; i < data.length; i++ ) {
var entry = data[i];
entry.distance = calculateDistance(entry.locationLongitude, entry.locationLatitude, LOCAL_LON, LOCAL_LAT);
}
现在将有一个按距离排序的数组CalculateInstance函数的作用和返回结果是什么?已将该部分代码添加到问题中。:)像这样尝试->CalculateInstance函数做什么和返回什么?已经在问题中添加了这部分代码。:)像这样尝试->CalculateInstance函数做什么和返回什么?已经在问题中添加了这部分代码。:)像这样尝试->CalculateInstance函数做什么和返回什么?已经在问题中添加了这部分代码。:)这样试试->距离是根据ajax调用生成的位置lat/lon计算的。获取后如何排序是我丢失的地方。您是否像步骤1中那样准备好了数据?距离将是基于用户当前位置的动态值。唯一可用的数据是问题的数组部分显示的数据。距离是根据ajax调用生成的位置lat/lon计算的。获取后如何排序是我丢失的地方。您是否像步骤1中那样准备好了数据?距离将是基于用户当前位置的动态值。唯一可用的数据是问题的数组部分显示的数据。距离是根据ajax调用生成的位置lat/lon计算的。获取后如何排序是我丢失的地方。您是否像步骤1中那样准备好了数据?距离将是基于用户当前位置的动态值。唯一可用的数据是问题的数组部分显示的数据。距离是根据ajax调用生成的位置lat/lon计算的。获取后如何排序是我丢失的地方。您是否像步骤1中那样准备好了数据?距离将是基于用户当前位置的动态值。唯一可用的数据是问题的数组部分显示的数据。