javascript - Google place Api find nearby place with distance between current place and nearby place with sorting -


I am trying to find nearby places and calculate the distance from the current place to the nearest places. And then I want to show everyone that the place in a table sorts the growing sequence of distance from the current location. Now I am

  1. Find nearby places < / Li>
  2. Find the distance from the current place to the nearest place
  3. Every place and place Display the order in the order because it has been received as a response from Google. I have added the data as a Jason array and added it to the console

    I Sort the array as a serial array instead of a direct result, instead of step3. Can anyone help me out with this ???

    JQuery mark = new google.maps.Marker ( {Status: obj.geometry.location, map: map, title: obj.nam e}); Warning (obj.name); Var lat = document.getElementById ('lat'). value; Var tall = document.getElementById ('LNG'). Values; // warning (lat); // warning (long); Var p1 = new google.maps.LatLng (latitude, long); Var p2 = new google.maps.LatLng (obj.geometry.location.lat (), obj.geometry.location.lng ()); Google.maps.LatLng.prototype.distanceFrom = function (latlng) {var lat = [this.lat (), latlng.lat ()] var lng = [this.lng (), latlng.lng ()] var R = 6378137; Var DLT = (lat [1] -Lat [0]) * Math PI / 180; Var DLNG = (LNG [1] -Lang [0]) * Math. PI / 180; Var a = Math.sin (dLat / 2) * Math.sin (dLat / 2) + Math.cos (lat [0] * Math.PI / 180) * Math.cos (latitude [1] * Math.PI / 180) * Math. Sin (DLNG / 2) * Math. Sin (DLNG / 2); Var c = 2 * Math.atan2 (Math.sqrt (a), Math.sqrt (1-A)); Var D = R * C; Return Mathematics. (D); } // var loc1 = new GLatLng (latitude, long); // var loc2 = new GLatLng (obj.geometry.location.lat (), obj.geometry.location.lng ()); Var dist = p2 dynastensom (p1); // warning (district / 1000 + 'meters'); Var distn = dist / 1000; ('& Lt; tr & gt; & lt; td & gt;' + obj.name + '& lt; / td & gt; & lt; & lt; td & gt;' + Friend + '& lt; / TD & gt; & lt; / tr & gt; '); Datas.push ({app: obj.name, message: distn}); //alert(google.maps.geometry.spherical.computeDistanceBetween(p1, p2) + 'Sa'); Markers.push (mark); // ready info window var infowindow = new google.maps.InfoWindow ({content: ' & lt; font style = "color: # 000;" & Gt; '+ Obj.name +'
    Rating: '+ obj.rating +'
    Proximity: '+ obj.vicinity +' & lt; / font & gt; ; '}); // Add Event Handler to the current marker google.maps.event.addListener (icon, 'click', function) () {clearInfos (); Infowindow.open (map, symbol);}); Infos.push (infowindow); Console.log (datas); // parse (data); }

    JSON data output (sample) may vary, but the distance field is
      [["place": "Ta'mm" , "Distance" ": 1.193}, {" location ":" bolthazar "," distance ": 1.127}, {" location ":" tribeca grill "," distance ": 0.678}, {" location ":" Lombardy pizza {"Location": "Best Western Boveri Hanbi Hotel", "Distance": 1.015}, {"Location:" "Distance": 1.179}, {"Location": "Whole Food Market", "Distance": 0.484}, {" Location ":" Les "(" location ":" shake shock "," distance ": 0.782}, {" location ":" "" "" "" "" "" "" "" ":" cafe lyrics " "Distance": 1.367}, "{" Est "", "Distance": "distance": 0.64}, {"location": "ninja new york", "distance": 0.397}, {"location": "la esquina", "distance": 1.056}, {"location" ("Location": "farmer", "distance": 1.277}, {"location": "apocalypse", "location": "ninja new york" ("location": "joe of shanghai", "distance": 0.697}, {"location" , "Distance": 0.658}, {"location": "cafe 1668", "distance": 0.436}, {"location": "rice to riches", "distance": 1.199}, {"location": "sabwei "Restaurants", "Distance": 0.382}, {"Location": "Bo" Answer "," Distance "," Distance ": 0.808}]    

    site libr There is a square in the ray which allows you to get results in a particular order. Please see

      var request = {place: coors, rank by: google.maps.places.RankBy.DISTANCE}; Var service = new google.maps.places.PlacesService (map); Service.search (request, callback);   

    To calculate the distance between 2 points, you can use geometry libraries, which has a computeDistanceBetween method. var distance = google.maps.geometry.spherical.computeDistanceBetween (A, B);

    If 2 are using the mentioned libraries, be sure to include them in the API script call.

      https://maps.googleapis.com/maps/Api/JS? Sensor = false and libraries = places, geometry   

    Hope this helps!

    Comments

    Popular posts from this blog

    ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

    Matlab transpose a table vector -

    c# - Textbox not clickable but editable -