I am struggling to display markers on a map for 20 restaurants from a JSON file. It seems like I may not be retrieving the data correctly. Any help or guidance in the right direction would be greatly appreciated.
My current code is as follows:
var map;
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(55.9753905, -1.6236163),
zoom: 12,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new
google.maps.Map(document.getElementById("EstablishmentCollection"),
mapOptions);
$.getJSON("'FHRS_json.json'", function(json1) {
$.each(json1, function(key, data) {
var latLng = new google.maps.LatLng(data.lat, data.lng);
// Creating a marker and putting it on the map
var marker = new google.maps.Marker({
position: latLng,
title: data.BusinessName
});
marker.setMap(map);
});
});
Here is a snippet of the beginning of the JSON file which contains information about various restaurants.
{
"FHRSEstablishment": {
"-xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
"Header": {
"ExtractDate": "2018-02-03",
"ItemCount": "2369",
"ReturnCode": "Success"
},
"EstablishmentCollection": {
"EstablishmentDetail": [
{
"FHRSID": "1011573",
"LocalAuthorityBusinessID": "17/00395/MIXED",
"BusinessName": "#Central",
"BusinessType": "Pub/bar/nightclub",
"BusinessTypeID": "7843",
"AddressLine1": "15 Marlborough Crescent",
"AddressLine2": "Newcastle upon Tyne",
"PostCode": "NE1 4EE",
"RatingValue": "AwaitingInspection",
"RatingKey": "fhrs_awaitinginspection_en-GB",
"RatingDate": { "-xsi:nil": "true" },
"LocalAuthorityCode": "416",
"LocalAuthorityName": "Newcastle Upon Tyne",
"LocalAuthorityWebSite": "http://www.newcastle.gov.uk/",
"LocalAuthorityEmailAddress": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="12626160527c7765717361667e773c75797b">[email protected]</a>",
"SchemeType": "FHRS",
"NewRatingPending": "False",
"Geocode": {
"Longitude": "-1.62244200000000",
"Latitude": "54.96785900000000"
}
},