Google Maps API - 最近点 - 更改排序顺序

Posted

技术标签:

【中文标题】Google Maps API - 最近点 - 更改排序顺序【英文标题】:Google Maps API - Closest points - Changing the sort order 【发布时间】:2016-05-20 03:38:37 【问题描述】:

我在不同地点有许多员工。当我接到一份工作时,我想把它分配给最近的员工。所以在这种情况下,分配的邮政编码为 06810。下面的当前代码首先使用纬度和经度对直线距离进行排名。然后使用谷歌方向,以英里为单位计算实际行驶距离,但仍按直线距离排序。我想要像第二组一样按实际行驶距离排序的结果。有人知道怎么做吗?谢谢

Original Results - http://vince.netau.net/vince.html    Using Zip Code 06810
Jen Alexander process 3:41.159977,-73.982356:      50348.52      54.3 Miles
Richard Henderson process 11:40.858696,-73.297249: 59009.38        92 Miles
Jim Thomas process 0:41.041599,-74.019554:         60252.91      55.5 Miles
Don James process 2:40.997704,-74.050598:          65365.08      59.5 Miles
John Smith process 1:40.986584,-74.290207:         82405.22        74 Miles
Al Bundy process 8:40.804319,-74.122668:           84834.76      71.2 Miles
Tim Hager process 7:40.691845,-73.969104:          87569.35      69.9 Miles
Ken Roberts process 5:40.754302,-74.409713:       105950.12      92.8 Miles
Vince Patera process 9:40.562019,-74.452335:      123497.86       101 Miles
Thomas Glenn process 10:40.291759,-74.343231:     142031.60       109 Miles
Tom Jones process 4:40.001475,-75.0268:           202567.94       153 Miles
Kevin James process 6:39.82534,-74.919937:        212467.19       155 Miles

Results I want
Jen Alexander process 3:41.159977,-73.982356:      50348.52      54.3 Miles
Jim Thomas process 0:41.041599,-74.019554:         60252.91      55.5 Miles
Don James process 2:40.997704,-74.050598:          65365.08      59.5 Miles
Tim Hager process 7:40.691845,-73.969104:          87569.35      69.9 Miles
Al Bundy process 8:40.804319,-74.122668:           84834.76      71.2 Miles
John Smith process 1:40.986584,-74.290207:         82405.22        74 Miles  
Richard Henderson process 11:40.858696,-73.297249: 59009.38        92 Miles
Ken Roberts process 5:40.754302,-74.409713:       105950.12      92.8 Miles
Vince Patera process 9:40.562019,-74.452335:      123497.86       101 Miles
Thomas Glenn process 10:40.291759,-74.343231:     142031.60       109 Miles
Tom Jones process 4:40.001475,-75.0268:           202567.94       153 Miles
Kevin James process 6:39.82534,-74.919937:        212467.19       155 Miles

代码:

<!DOCTYPE html>
 <html>
   <head>
     <title>Google Maps javascript API v3 Example: Map Simple</title>
     <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
     <meta charset="utf-8">
     <style>
       html, body, #map_canvas 
         margin: 0;
         padding: 0;
         height: 100%;
       
     </style>
<script src="https://maps.googleapis.com/maps/api/js?libraries=geometry&sensor=false"></script>
<script type="text/javascript">     
// Store Name[0],delivery[1],Address[2],Delivery Zone[3],Coordinates[4] data from FusionTables pizza stores example
var locations = [
["Jim Thomas","no","12 Williams Rd, Montvale, NJ","<Polygon><outerBoundaryIs><LinearRing><coordinates>-122.121277,37.386799,0 -122.158012,37.4168,0 -122.158012,37.448151,0 -122.142906,37.456055,0 -122.118874,37.45224,0 -122.107544,37.437793,0 -122.102737,37.422526,0 -122.113037,37.414618,0 -122.121277,37.386799,0   </coordinates></LinearRing></outerBoundaryIs></Polygon>","41.041599,-74.019554","http://maps.google.com/mapfiles/ms/icons/blue.png"],
["John Smith","yes","8 Craig Place, Pompton Lakes, NJ","<Polygon><outerBoundaryIs><LinearRing><coordinates>-122.200928,37.438611,0 -122.158012,37.4168,0 -122.158012,37.448151,0 -122.142906,37.456055,0 -122.144623,37.475948,0 -122.164192,37.481125,0 -122.189255,37.478673,0 -122.208481,37.468319,0 -122.201271,37.438338,0 </coordinates></LinearRing></outerBoundaryIs></Polygon>","40.986584,-74.290207","http://maps.google.com/mapfiles/ms/icons/green.png"],
["Don James","no","689 Fern St, Township of Washington, NJ","<Polygon><outerBoundaryIs><LinearRing><coordinates>-122.304268,37.516534,0 -122.300835,37.505096,0 -122.262383,37.481669,0 -122.242813,37.502917,0 -122.244186,37.534232,0 -122.269249,37.550021,0 -122.291222,37.545122,0 -122.302895,37.537499,0 -122.304268,37.516534,0 </coordinates></LinearRing></outerBoundaryIs></Polygon>","40.997704,-74.050598","http://maps.google.com/mapfiles/ms/icons/red.png"],
["Jen Alexander","yes","45 Heritage Dr, New City, NY","<Polygon><outerBoundaryIs><LinearRing><coordinates>-122.304268,37.516534,0 -122.348557,37.538044,0 -122.359886,37.56363,0 -122.364006,37.582405,0 -122.33654,37.589207,0 -122.281609,37.570433,0 -122.291222,37.545122,0 -122.302895,37.537499,0 -122.304268,37.516534,0 </coordinates></LinearRing></outerBoundaryIs></Polygon>","41.159977,-73.982356","http://maps.google.com/mapfiles/ms/icons/yellow.png"],
["Tom Jones","yes","263 W. Broad St, Palmyra, NJ","<Polygon><outerBoundaryIs><LinearRing><coordinates>-122.374306,37.548933,0 -122.348557,37.538044,0 -122.359886,37.56363,0 -122.364006,37.582405,0 -122.33654,37.589207,0 -122.359543,37.59764,0 -122.372246,37.604712,0 -122.417564,37.594648,0 -122.374306,37.548933,0 </coordinates></LinearRing></outerBoundaryIs></Polygon>","40.001475, -75.026800","http://maps.google.com/mapfiles/ms/icons/blue.png"],
["Ken Roberts","yes","169 Main St, Madison, NJ","<Polygon><outerBoundaryIs><LinearRing><coordinates>-122.462883,37.628916,0 -122.445374,37.639247,0 -122.426147,37.648762,0 -122.405205,37.642238,0 -122.400055,37.628644,0 -122.392159,37.610696,0 -122.372246,37.604712,0 -122.417564,37.594648,0 -122.462196,37.628644,0  </coordinates></LinearRing></outerBoundaryIs></Polygon>","40.754302, -74.409713","http://maps.google.com/mapfiles/ms/icons/green.png"],
["Kevin James","yes","90 Tenby Chase Dr, Voorhees, NJ","<Polygon><outerBoundaryIs><LinearRing><coordinates>-122.43576,37.790795,0 -122.449493,37.801646,0 -122.425461,37.809784,0 -122.402115,37.811411,0 -122.390442,37.794593,0 -122.408295,37.79188,0 -122.434387,37.789167,0 </coordinates></LinearRing></outerBoundaryIs></Polygon>","39.825340, -74.919937","http://maps.google.com/mapfiles/ms/icons/green.png"],
["Tim Hager","yes","208 Clinton Ave, ***lyn, NY","<Polygon><outerBoundaryIs><LinearRing><coordinates>-122.463398,37.760266,0 -122.477349,37.774785,0 -122.427349,37.774785,0 -122.429237,37.763658,0 -122.46357,37.760808,0</coordinates></LinearRing></outerBoundaryIs></Polygon>","40.691845, -73.969104","http://maps.google.com/mapfiles/ms/icons/green.png"],
["Al Bundy","yes","554 Page Ave, Lyndhurst, NJ","<Polygon><outerBoundaryIs><LinearRing><coordinates>-122.418766,37.747779,0 -122.425289,37.768951,0 -122.406063,37.769901,0 -122.406063,37.749679,0 -122.418251,37.747508,0 </coordinates></LinearRing></outerBoundaryIs></Polygon>","40.804319, -74.122668","http://maps.google.com/mapfiles/ms/icons/green.png"],
["Vince Patera","yes","12 Marissa Ct, Piscataway, NJ","<Polygon><outerBoundaryIs><LinearRing><coordinates>-122.121277,37.386799,0 -122.108917,37.362244,0 -122.077675,37.3385,0 -122.064285,37.378615,0 -122.069778,37.3898,0 -122.076645,37.402619,0 -122.078705,37.411619,0 -122.113037,37.414618,0 -122.121277,37.386799,0  </coordinates></LinearRing></outerBoundaryIs></Polygon>","40.562019, -74.452335","http://maps.google.com/mapfiles/ms/icons/green.png"],
["Thomas Glenn","no","8 Taylors Mills Rd, Manalapan, NJ","<Polygon><outerBoundaryIs><LinearRing><coordinates>-122.047119,37.33113,0 -122.065315,37.332495,0 -122.077675,37.3385,0 -122.064285,37.378615,0 -122.036819,37.385162,0 -122.006607,37.382162,0 -122.00386,37.342048,0 -122.047119,37.331403,0  </coordinates></LinearRing></outerBoundaryIs></Polygon>","40.291759, -74.343231","http://maps.google.com/mapfiles/ms/icons/blue.png"],
["Richard Henderson","no","27 Buhl Ln, East Northport, NY","<Polygon><outerBoundaryIs><LinearRing><coordinates>-121.935196,37.345051,0 -121.931076,37.294267,0 -121.871338,37.293721,0 -121.806793,37.293174,0 -121.798553,37.361426,0 -121.879578,37.36088,0 -121.934509,37.345597,0 -121.935196,37.345051,0 </coordinates></LinearRing></outerBoundaryIs></Polygon>","40.858696, -73.297249","http://maps.google.com/mapfiles/ms/icons/yellow.png"],
];
// alert(locations.length);

var geocoder = null;
var map = null;
var customerMarker = null;
var gmarkers = [];
var closest = [];
var directionsDisplay = new google.maps.DirectionsRenderer();;
var directionsService = new google.maps.DirectionsService();
var map;

function initialize() 
// alert("init");
  geocoder = new google.maps.Geocoder();
  map = new google.maps.Map(document.getElementById('map'), 
               
            zoom: 9,       
            center: new google.maps.LatLng(52.6699927, -0.7274620),       
            mapTypeId: google.maps.MapTypeId.ROADMAP     
        );      
  var infowindow = new google.maps.InfoWindow();      
  var marker, i;      
  var bounds = new google.maps.LatLngBounds();
  document.getElementById('info').innerHTML = "found "+locations.length+" locations<br>";
  for (i = 0; i < locations.length; i++)          
            var coordStr = locations[i][4];
        var coords = coordStr.split(",");
        var pt = new google.maps.LatLng(parseFloat(coords[0]),parseFloat(coords[1]));
            bounds.extend(pt);
            marker = new google.maps.Marker(         
                            position: pt,         
                            map: map,
                icon: locations[i][5],
                            address: locations[i][2],
                            title: locations[i][0],
                            html: locations[i][0]+"<br>"+locations[i][2]+"<br><br><a href='javascript:getDirections(customerMarker.getPosition(),&quot;"+locations[i][2]+"&quot;);'>Get Directions</a>"
                            );                              
            gmarkers.push(marker);
            google.maps.event.addListener(marker, 'click', (function(marker, i)          return function() 
                       infowindow.setContent(marker.html);
                        infowindow.open(map, marker);         
                   
        )
        (marker, i));     
    
    map.fitBounds(bounds);   



      function codeAddress() 
        var address = document.getElementById('address').value;
        geocoder.geocode(  'address': address, function(results, status) 
          if (status == google.maps.GeocoderStatus.OK) 
            map.setCenter(results[0].geometry.location);
        if (customerMarker) customerMarker.setMap(null);
            customerMarker = new google.maps.Marker(
                map: map,
                position: results[0].geometry.location
            );
        closest = findClosestN(results[0].geometry.location,12);
            // get driving distance
            closest = closest.splice(0,12);
            calculateDistances(results[0].geometry.location, closest,12);
           else 
            alert('Geocode was not successful for the following reason: ' + status);
          
        );
      

function findClosestN(pt,numberOfResults) 
   var closest = [];
   document.getElementById('info').innerHTML += "processing "+gmarkers.length+"<br>";
   for (var i=0; i<gmarkers.length;i++) 
     gmarkers[i].distance = google.maps.geometry.spherical.computeDistanceBetween(pt,gmarkers[i].getPosition());
     document.getElementById('info').innerHTML += "process "+i+":"+gmarkers[i].getPosition().toUrlValue(6)+":"+gmarkers[i].distance.toFixed(2)+"<br>";
     gmarkers[i].setMap(null);
     closest.push(gmarkers[i]);
     closest.sort(sortByDist);  
   

   return closest;


function sortByDist(a,b)  
 return (a.distance- b.distance)



function calculateDistances(pt,closest,numberOfResults) 
  var service = new google.maps.DistanceMatrixService();
  var request =    
      origins: [pt],
      destinations: [],
      travelMode: google.maps.TravelMode.DRIVING,
      unitSystem: google.maps.UnitSystem.IMPERIAL,
      avoidHighways: false,
      avoidTolls: false
    ;
  for (var i=0; i<closest.length; i++) request.destinations.push(closest[i].getPosition());
  service.getDistanceMatrix(request, function (response, status) 
    if (status != google.maps.DistanceMatrixStatus.OK) 
      alert('Error was: ' + status);
     else 
      var origins = response.originAddresses;
      var destinations = response.destinationAddresses;
      var outputDiv = document.getElementById('side_bar');
      outputDiv.innerHTML = '';

      var results = response.rows[0].elements;
      for (var i = 0; i < numberOfResults; i++) 
        closest[i].setMap(map);
        outputDiv.innerHTML += "<a href='javascript:google.maps.event.trigger(closest["+i+"],\"click\");'>"+closest[i].title + '</a><br>' + closest[i].address+"<br>"
            + results[i].distance.text + ' appoximately '
            + results[i].duration.text + '<br><hr>';
      
    
  );


function getDirections(origin, destination) 
  var request = 
      origin:origin,
      destination:destination,
      travelMode: google.maps.DirectionsTravelMode.DRIVING
  ;
  directionsService.route(request, function(response, status) 
    if (status == google.maps.DirectionsStatus.OK) 
      directionsDisplay.setMap(map);
      directionsDisplay.setDirections(response);
      directionsDisplay.setPanel(document.getElementById('side_bar'));
    
  );


google.maps.event.addDomListener(window, 'load', initialize);
</script> 
   </head>
   <body>
<table border="1"><tr><td>
     <div id="map" style="height: 600px; width:800px;"></div>
</td><td>
     <div id="side_bar"></div>
</td></tr></table>
<input id="address" type="text" value="Palo Alto, CA"></input>
<input type="button" value="Search" onclick="codeAddress();"></input>
<div id="info"></div>
   </body>
 </html>

【问题讨论】:

【参考方案1】:

按距离对结果数组进行排序。

 results.sort(sortByDistDM);

sortByDistDM 在哪里:

function sortByDistDM(a,b) 
   return (a.distance.value- b.distance.value)

updated page

function calculateDistances(pt,closest,numberOfResults) 
  var service = new google.maps.DistanceMatrixService();
  var request =    
      origins: [pt],
      destinations: [],
      travelMode: google.maps.TravelMode.DRIVING,
      unitSystem: google.maps.UnitSystem.METRIC,
      avoidHighways: false,
      avoidTolls: false
    ;
  for (var i=0; i<closest.length; i++) 
    request.destinations.push(closest[i].getPosition());
  
  service.getDistanceMatrix(request, function (response, status) 
    if (status != google.maps.DistanceMatrixStatus.OK) 
      alert('Error was: ' + status);
     else 
      var origins = response.originAddresses;
      var destinations = response.destinationAddresses;
      var outputDiv = document.getElementById('side_bar');
      outputDiv.innerHTML = '';

      var results = response.rows[0].elements;
      // save title, address and index of marker in record for sorting
      for (var i=0; i<closest.length;i++) 
         results[i].title = closest[i].title;
         results[i].address = closest[i].address;
     results[i].idx_closestMark = i;
      
      results.sort(sortByDistDM);
      for (var i = 0; ((i < numberOfResults) && (i < closest.length)); i++) 
        closest[i].setMap(map);
        outputDiv.innerHTML += "<a href='javascript:google.maps.event.trigger(closest["+results[i].idx_closestMark+"],\"click\");'>"+results[i].title + '</a><br>' + results[i].address+"<br>"
            + results[i].distance.text + ' appoximately '
            + results[i].duration.text + '<br><hr>';
      
    
  );


function sortByDistDM(a,b) 
   return (a.distance.value- b.distance.value)

代码 sn-p:

var geocoder = null;
var map = null;
var customerMarker = null;
var gmarkers = [];
var closest = [];

function initialize() 
  geocoder = new google.maps.Geocoder();
  map = new google.maps.Map(document.getElementById('map'), 
    zoom: 9,
    center: new google.maps.LatLng(52.6699927, -0.7274620),
    mapTypeId: google.maps.MapTypeId.ROADMAP
  );
  var infowindow = new google.maps.InfoWindow();
  var marker, i;
  var bounds = new google.maps.LatLngBounds();
  document.getElementById('info').innerHTML = "found " + locations.length + " locations<br>";
  for (i = 0; i < locations.length; i++) 
    var coordStr = locations[i][4];
    var coords = coordStr.split(",");
    var pt = new google.maps.LatLng(parseFloat(coords[0]), parseFloat(coords[1]));
    bounds.extend(pt);
    marker = new google.maps.Marker(
      position: pt,
      map: map,
      icon: locations[i][5],
      address: locations[i][2],
      title: locations[i][0],
      html: locations[i][0] + "<br>" + locations[i][2]
    );
    gmarkers.push(marker);
    google.maps.event.addListener(marker, 'click', (function(marker, i) 
        return function() 
          infowindow.setContent(marker.html);
          infowindow.open(map, marker);
        
      )
      (marker, i));
  
  map.fitBounds(bounds);



function codeAddress() 
  var numberOfResults = 14;
  var address = document.getElementById('address').value;
  geocoder.geocode(
    'address': address
  , function(results, status) 
    if (status == google.maps.GeocoderStatus.OK) 
      map.setCenter(results[0].geometry.location);
      if (customerMarker) customerMarker.setMap(null);
      customerMarker = new google.maps.Marker(
        map: map,
        position: results[0].geometry.location
      );
      closest = findClosestN(results[0].geometry.location, numberOfResults);
      // get driving distance
      closest = closest.splice(0, numberOfResults);
      calculateDistances(results[0].geometry.location, closest, numberOfResults);
     else 
      alert('Geocode was not successful for the following reason: ' + status);
    
  );


function findClosestN(pt, numberOfResults) 
  var closest = [];
  document.getElementById('info').innerHTML += "processing " + gmarkers.length + "<br>";
  for (var i = 0; i < gmarkers.length; i++) 
    gmarkers[i].distance = google.maps.geometry.spherical.computeDistanceBetween(pt, gmarkers[i].getPosition());
    document.getElementById('info').innerHTML += "process " + i + ":" + gmarkers[i].getPosition().toUrlValue(6) + ":" + gmarkers[i].distance.toFixed(2) + "<br>";
    gmarkers[i].setMap(null);
    closest.push(gmarkers[i]);
  
  closest.sort(sortByDist);
  return closest;


function sortByDist(a, b) 
  return (a.distance - b.distance)


function calculateDistances(pt, closest, numberOfResults) 
  var service = new google.maps.DistanceMatrixService();
  var request = 
    origins: [pt],
    destinations: [],
    travelMode: google.maps.TravelMode.DRIVING,
    unitSystem: google.maps.UnitSystem.METRIC,
    avoidHighways: false,
    avoidTolls: false
  ;
  for (var i = 0; i < closest.length; i++) 
    request.destinations.push(closest[i].getPosition());
  
  service.getDistanceMatrix(request, function(response, status) 
    if (status != google.maps.DistanceMatrixStatus.OK) 
      alert('Error was: ' + status);
     else 
      var origins = response.originAddresses;
      var destinations = response.destinationAddresses;
      var outputDiv = document.getElementById('side_bar');
      outputDiv.innerHTML = '';

      var results = response.rows[0].elements;
      // save title and address in record for sorting
      for (var i = 0; i < closest.length; i++) 
        results[i].title = closest[i].title;
        results[i].address = closest[i].address;
        results[i].idx_closestMark = i;
      
      results.sort(sortByDistDM);
      for (var i = 0;
        ((i < numberOfResults) && (i < closest.length)); i++) 
        closest[i].setMap(map);
        outputDiv.innerHTML += "<a href='javascript:google.maps.event.trigger(closest[" + results[i].idx_closestMark + "],\"click\");'>" + results[i].title + '</a><br>' + results[i].address + "<br>" + results[i].distance.text + ' appoximately ' + results[i].duration.text + '<br><hr>';
      
    
  );


function sortByDistDM(a, b) 
  return (a.distance.value - b.distance.value)


google.maps.event.addDomListener(window, 'load', initialize);

// Store Name[0],delivery[1],Address[2],Delivery Zone[3],Coordinates[4] data from FusionTables pizza stores example
var locations = [
  ["John's Pizza", "no", "400 University Ave, Palo Alto, CA", "<Polygon><outerBoundaryIs><LinearRing><coordinates>-122.121277,37.386799,0 -122.158012,37.4168,0 -122.158012,37.448151,0 -122.142906,37.456055,0 -122.118874,37.45224,0 -122.107544,37.437793,0 -122.102737,37.422526,0 -122.113037,37.414618,0 -122.121277,37.386799,0   </coordinates></LinearRing></outerBoundaryIs></Polygon>", "37.447038,-122.160575", "http://maps.google.com/mapfiles/ms/icons/blue.png"],
  ["JJs Express", "yes", "1000 Santa Cruz Ave, Menlo Park, CA", "<Polygon><outerBoundaryIs><LinearRing><coordinates>-122.200928,37.438611,0 -122.158012,37.4168,0 -122.158012,37.448151,0 -122.142906,37.456055,0 -122.144623,37.475948,0 -122.164192,37.481125,0 -122.189255,37.478673,0 -122.208481,37.468319,0 -122.201271,37.438338,0 </coordinates></LinearRing></outerBoundaryIs></Polygon>", "37.448638,-122.187176", "http://maps.google.com/mapfiles/ms/icons/green.png"],
  ["John Paul's Pizzeria", "no", "1100 El Camino Real, Belmont, CA", "<Polygon><outerBoundaryIs><LinearRing><coordinates>-122.304268,37.516534,0 -122.300835,37.505096,0 -122.262383,37.481669,0 -122.242813,37.502917,0 -122.244186,37.534232,0 -122.269249,37.550021,0 -122.291222,37.545122,0 -122.302895,37.537499,0 -122.304268,37.516534,0 </coordinates></LinearRing></outerBoundaryIs></Polygon>", "37.520436,-122.275978", "http://maps.google.com/mapfiles/ms/icons/red.png"],
  ["JJs Express", "yes", "300 E 4th Ave, San Mateo, CA", "<Polygon><outerBoundaryIs><LinearRing><coordinates>-122.304268,37.516534,0 -122.348557,37.538044,0 -122.359886,37.56363,0 -122.364006,37.582405,0 -122.33654,37.589207,0 -122.281609,37.570433,0 -122.291222,37.545122,0 -122.302895,37.537499,0 -122.304268,37.516534,0 </coordinates></LinearRing></outerBoundaryIs></Polygon>", "37.564435,-122.322080", "http://maps.google.com/mapfiles/ms/icons/green.png"],
  ["John's Pizza", "yes", "1400 Broadway Ave, Burlingame, CA", "<Polygon><outerBoundaryIs><LinearRing><coordinates>-122.374306,37.548933,0 -122.348557,37.538044,0 -122.359886,37.56363,0 -122.364006,37.582405,0 -122.33654,37.589207,0 -122.359543,37.59764,0 -122.372246,37.604712,0 -122.417564,37.594648,0 -122.374306,37.548933,0 </coordinates></LinearRing></outerBoundaryIs></Polygon>", "37.584935,-122.366182", "http://maps.google.com/mapfiles/ms/icons/blue.png"],
  ["JJs Express", "yes", "700 San Bruno Ave, San Bruno, CA", "<Polygon><outerBoundaryIs><LinearRing><coordinates>-122.462883,37.628916,0 -122.445374,37.639247,0 -122.426147,37.648762,0 -122.405205,37.642238,0 -122.400055,37.628644,0 -122.392159,37.610696,0 -122.372246,37.604712,0 -122.417564,37.594648,0 -122.462196,37.628644,0  </coordinates></LinearRing></outerBoundaryIs></Polygon>", "37.630934,-122.406883", "http://maps.google.com/mapfiles/ms/icons/green.png"],
  ["JJs Express", "yes", "300 Beach St, San Francisco, CA", "<Polygon><outerBoundaryIs><LinearRing><coordinates>-122.43576,37.790795,0 -122.449493,37.801646,0 -122.425461,37.809784,0 -122.402115,37.811411,0 -122.390442,37.794593,0 -122.408295,37.79188,0 -122.434387,37.789167,0 </coordinates></LinearRing></outerBoundaryIs></Polygon>", "37.807628,-122.413782", "http://maps.google.com/mapfiles/ms/icons/green.png"],
  ["JJs Express", "yes", "1400 Haight St, San Francisco, CA", "<Polygon><outerBoundaryIs><LinearRing><coordinates>-122.463398,37.760266,0 -122.477349,37.774785,0 -122.427349,37.774785,0 -122.429237,37.763658,0 -122.46357,37.760808,0</coordinates></LinearRing></outerBoundaryIs></Polygon>", "37.770129,-122.445082", "http://maps.google.com/mapfiles/ms/icons/green.png"],
  ["JJs Express", "yes", "2400 Mission St, San Francisco, CA", "<Polygon><outerBoundaryIs><LinearRing><coordinates>-122.418766,37.747779,0 -122.425289,37.768951,0 -122.406063,37.769901,0 -122.406063,37.749679,0 -122.418251,37.747508,0 </coordinates></LinearRing></outerBoundaryIs></Polygon>", "37.758630,-122.419082", "http://maps.google.com/mapfiles/ms/icons/green.png"],
  ["JJs Express", "yes", "500 Castro St, Mountain View, CA", "<Polygon><outerBoundaryIs><LinearRing><coordinates>-122.121277,37.386799,0 -122.108917,37.362244,0 -122.077675,37.3385,0 -122.064285,37.378615,0 -122.069778,37.3898,0 -122.076645,37.402619,0 -122.078705,37.411619,0 -122.113037,37.414618,0 -122.121277,37.386799,0  </coordinates></LinearRing></outerBoundaryIs></Polygon>", "37.390040,-122.081573", "http://maps.google.com/mapfiles/ms/icons/green.png"],
  ["John's Pizza", "no", "100 S Murphy Ave, Sunnyvale, CA", "<Polygon><outerBoundaryIs><LinearRing><coordinates>-122.047119,37.33113,0 -122.065315,37.332495,0 -122.077675,37.3385,0 -122.064285,37.378615,0 -122.036819,37.385162,0 -122.006607,37.382162,0 -122.00386,37.342048,0 -122.047119,37.331403,0  </coordinates></LinearRing></outerBoundaryIs></Polygon>", "37.377441,-122.030071", "http://maps.google.com/mapfiles/ms/icons/blue.png"],
  ["John's Pizza", "no", "1200 Curtner Ave, San Jose, CA", "<Polygon><outerBoundaryIs><LinearRing><coordinates>-121.935196,37.345051,0 -121.931076,37.294267,0 -121.871338,37.293721,0 -121.806793,37.293174,0 -121.798553,37.361426,0 -121.879578,37.36088,0 -121.934509,37.345597,0 -121.935196,37.345051,0 </coordinates></LinearRing></outerBoundaryIs></Polygon>", "37.288742,-121.890765", "http://maps.google.com/mapfiles/ms/icons/blue.png"],
  ["John's Pizza", "yes", "700 Blossom Hill Rd, San Jose, CA", "<Polygon><outerBoundaryIs><LinearRing><coordinates>-121.935883,37.253287,0 -121.931076,37.294267,0 -121.871338,37.293721,0 -121.806793,37.293174,0 -121.790657,37.234702,0 -121.852455,37.223221,0 -121.935539,37.253014,0 </coordinates></LinearRing></outerBoundaryIs></Polygon>", "37.250543,-121.846563", "http://maps.google.com/mapfiles/ms/icons/blue.png"],
  ["John's Pizza", "yes", "100 N Milpitas Blvd, Milpitas, CA", "<Polygon><outerBoundaryIs><LinearRing><coordinates>-121.947556,37.435612,0 -121.934509,37.476493,0 -121.893311,37.469409,0 -121.852798,37.429615,0 -121.843872,37.400165,0 -121.887817,37.3898,0 -121.959915,37.420345,0 -121.959915,37.427979,0 -121.948929,37.435612,0 -121.947556,37.435612,0</coordinates></LinearRing></outerBoundaryIs></Polygon>", "37.434113,-121.901139", "http://maps.google.com/mapfiles/ms/icons/blue.png"],
  ["John's Pizza", "yes", "3300 Mowry Blvd, Fremont, CA", "<Polygon><outerBoundaryIs><LinearRing><coordinates>-122.02343,37.52198,0 -122.023773,37.558731,0 -121.989784,37.573426,0 -121.959572,37.566351,0 -121.944466,37.544305,0 -121.967125,37.520891,0 -122.023087,37.522525,0</coordinates></LinearRing></outerBoundaryIs></Polygon>", "37.552773,-121.985153", "http://maps.google.com/mapfiles/ms/icons/blue.png"]
];
html,
body, #map 
  margin: 0;
  padding: 0;
  height: 100%;
  overflow:auto;
<script src="https://maps.googleapis.com/maps/api/js?libraries=geometry&key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk"></script>
<table border="1" style="height:90%; width:100%;">
  <tr style="height:100%; width:100%;">
    <td valign="top" style="height:100%; width:100%;">
      <div id="map"></div>
    </td>
    <td>
      <div id="side_bar" style="height: 500px; overflow:auto;"></div>
    </td>
  </tr>
</table>
<input id="address" type="text" value="Palo Alto, CA" />
<input type="button" value="Search" onclick="codeAddress();" />
<div id="info"></div>

【讨论】:

以上是关于Google Maps API - 最近点 - 更改排序顺序的主要内容,如果未能解决你的问题,请参考以下文章

在 maps.google.com 上的缩放比在 Google Maps API v3 上更流畅

使用 Google Maps API 配置热图叠加层

Google Maps Api v3 - 查找最近的标记

如何更改 Google Maps API V3 中的图标颜色?

半径/最近的结果 - Google Maps API

Google maps api v2如何找到最近的位置