I have an input for searching for a store number to find its position on the map. The JSON is hosted here, but I will leave a snippet below.
"22": {
"Lat": "43.1022902",
"Address": "3065 NY-50 Saratoga Springs NY 12866 USA",
"Long": "-73.7377407"
},
"23": {
"Lat": "40.3581539",
"Address": "2767 Papermill Rd Reading PA 19610 USA",
"Long": "-75.9850194"
},
"24": {
"Lat": "40.1893263",
"Address": "347 Washington Rd Washington PA 15301 USA",
"Long": "-80.2265591"
},
"26": {
"Lat": "38.0240453",
"Address": "1968 Pavilion Way Lexington KY 40509 USA",
"Long": "-84.41592919999999"
}
The function is meant to take the value of the search and get the lat and long values of that. So searchString = 23 would give the following;
"Lat": "40.3581539",
"Address": "2767 Papermill Rd Reading PA 19610 USA",
"Long": "-75.9850194"
Here is what I tried below:
$('#search-bar').submit(function () {
searchString = $("#search").val();
$.getJSON(allStoresJson, function (data) {
query = allStoresJson[searchString]
console.log(query)
lat = query.Lat
long = query.Long
})
var point = new L.LatLng(lat, long);
map.setView(point, 11, {
animation: true
})
return false;
});
allStoresJsonis the URL that he downloads the JSON from.datais the JSON, so it should bedata[searchString]