I am trying to work through the example from Chapter 5 of the Leaflet.js succinctly book - but cannot get any of the coffee shops to show on my map.
Some of the commands give me errors so I've looked for workarounds, and I suspect the problem could be as simple as files not being in the correct place. Is there an idiot's guide to using databases with leaflet I could follow? Or can someone see the error I am making?
My set up:
/Applications/xampp/xamppfiles/bin/mysql -u root -p
create database leafletDB mysql –uroot –pleaflet < "C:\CoffeeShops.sql"; to work, even changing the path to CoffeeShops.sql)USE leafletDB; SHOW TABLES; and SELECT COUNT(*) FROM coffeeshops; all gave the expected results./Applications/XAMPP/xamppfiles/var/mysql//Applications/XAMPP/xamppfiles/htdocs/CoffeeExample folder, which is the same file as the listing43.html file (the file that creates the map)The map displays, any markers coded directly into the html file display - but nothing from the database.
What have I got wrong?
As requested here is a copy of all the code - sorry for how long this is
listing43.html
<!DOCTYPE html>
<html>
<head>
<title>My Leaflet.js Map</title>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.css" />
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.3.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.3/leaflet.js">
</script>
<style>
html,
body,
#map {
height: 100%;
}
</style>
<script type="text/javascript">
function init() {
var map = L.map('map').setView([42.362, -71.085], 13);
// OSM Mapnik
var osmLink = "<a href='http://www.openstreetmap.org'>Open StreetMap</a>";
L.tileLayer(
'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© ' + osmLink,
maxZoom: 18
}).addTo(map);
showCoffeeShops(map);
L.marker([42.362,-71.085]).addTo(map)
.bindPopup('A pretty CSS3 popup.<br> Easily customizable.')
.openPopup();
}
function showCoffeeShops(map) {
var mugIcon = L.icon({
iconUrl: "mug.png",
iconSize: [25,25]
});
$.getJSON("coffee.php", function(data) {
for (var i = 0; i < data.length; i++) {
var location = new L.LatLng(data[i].Latitude, data[i].Longitude);
var name = data[i].Name;
var addr1 = data[i].Address1;
if(data[i].Address2.length > 1) {
addr2 = data[i].Address2 + "</br>";
} else {
addr2 = "";
}
var cityzip = data[i].City + ", " + data[i].Zip;
var visits = data[i].Visits;
var marker = new L.Marker(location, {
icon: mugIcon,
title: name
});
var content = "<h2>" + name + "</h2>"
+ "<p>" + addr1 + "</br>" + addr2
+ cityzip + "</p>"
+ "<p>Visits: <b>" + visits + "</b></p>";
marker.bindPopup(content, {
maxWidth: '200'
});
marker.addTo(map);
}
});
}
</script>
</head>
<body onload="init()">
<div id="map"></div>
</body>
</html>
coffee.php
<?php
$db = new PDO("mysql:host=localhost;dbname=leafletDB", "root", "leaflet");
$sql = "SELECT * FROM CoffeeShops WHERE City='Boston'";
$rs = $db->query($sql);
if (!$rs) {
echo "An SQL error occured.\n";
exit;
}
$rows = array();
while($r = $rs->fetch(PDO::FETCH_ASSOC)) {
$rows[] = $r;
}
print json_encode($rows);
$db = NULL;
?>
CoffeeShops.sql (note this has been truncated, there are a few thousand lines in the database)
-- phpMyAdmin SQL Dump
-- version 4.4.14
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Nov 24, 2015 at 05:56 PM
-- Server version: 5.6.26
-- PHP Version: 5.6.12
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
--
-- Database: `leafletDB`
--
USE leafletDB;
-- --------------------------------------------------------
--
-- Table structure for table `CoffeeShops`
--
DROP TABLE IF EXISTS `CoffeeShops`;
CREATE TABLE IF NOT EXISTS `coffeeshops` (
`StoreID` int(11) DEFAULT NULL,
`Name` varchar(255) DEFAULT NULL,
`Telephone` varchar(25) NOT NULL,
`Address1` varchar(255) DEFAULT NULL,
`Address2` varchar(255) DEFAULT NULL,
`City` varchar(50) DEFAULT NULL,
`State` char(2) NOT NULL,
`Zipcode` char(9) NOT NULL,
`Latitude` decimal(9,6) DEFAULT NULL,
`Longitude` decimal(9,6) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Truncate table before insert `CoffeeShops`
--
TRUNCATE TABLE `CoffeeShops`;
--
-- Dumping data for table `CoffeeShops`
--
INSERT INTO `CoffeeShops` (`StoreID`, `Name`, `Telephone`, `Address1`, `Address2`, `City`, `State`, `Zipcode`, `Latitude`, `Longitude`) VALUES
(11854, 'Epping Main St', '603-679-8789', '96 Calef Highway', '', 'Epping', 'NH', '03042-222', '43.031873', '-71.073203'),
(79420, 'Stop & Shop-Exeter #204', '603-772-1783', '139 Portsmouth Ave', '', 'Exeter', 'NH', '03833-210', '42.989763', '-70.932044'),
(3872, 'Target Greenland T-2530', '603-501-1470', '1450 Greenland Rd', '', 'Greenland', 'NH', '03840-243', '43.048710', '-70.816345'),
(13448, 'Seabrook, Lafayette Rd', '603-474-3674', '271 Lafayette Rd', '', 'Seabrook', 'NH', '03874-451', '42.882128', '-70.868080'),
(10325, 'Portsmouth, Woodbury Avenue', '603-436-1547', '1855 Woodbury Avenue', '', 'Portsmouth', 'NH', '03801-322', '43.092318', '-70.792327'),
(7459, 'Portsmouth/Market Square/Cigar Stor', '603-433-4471', '1 Market Square, Suite 17D', 'Suite 17D', 'Portsmouth', 'NH', '03801-401', '43.077086', '-70.758064'),
(11182, 'Haverhill, 1116 Main St', '978-372-3485', '1116 Main Street', '', 'Haverhill', 'MA', '01830-141', '42.807206', '-71.102071'),
(7329, 'Newburyport', '978-462-4475', '23 Market Square', '', 'Newburyport', 'MA', '01950-257', '42.811138', '-70.869501'),
(7907, 'Kittery', '207-451-9701', '306 Highway 1, M150', 'M150', 'Kittery', 'ME', '3904', '43.111116', '-70.734091'),
(76864, 'Target Haverhill T-2325', '978-377-9003', '35 Computer Dr', '', 'Haverhill', 'MA', '01832-123', '42.786955', '-71.115836'),
(9991, 'Dover, NH', '603-742-1867', '11 Webb Place', '', 'Dover', 'NH', '03820-240', '43.221256', '-70.888115'),
(76677, 'Target - Somersworth T-2182', '603-692-6750', '11 Andrews Rd', '', 'Somersworth', 'NH', '03878-104', '43.232909', '-70.881800'),
(7570, 'Methuen/The Loop', '978-681-5284', '90 Pleasant Valley St, Unit 170', 'Unit 170', 'Methuen', 'MA', '01844-728', '42.744153', '-71.157345'),
(16926, 'Target Salem T-1186', '603-870-0071', '203 S Broadway', '', 'Salem', 'NH', '03079-337', '42.764387', '-71.216689'),
(76855, 'Target Methuen T-2287', '978-983-0013', '67 Pleasant Valley St', '', 'Methuen', 'MA', '01844-720', '42.741881', '-71.160069'),
(13411, 'Manchester, S. Willow St.', '603-641-4839', '1111 South Willow St', '', 'Manchester', 'NH', '03103-403', '42.960288', '-71.438445'),
(75663, 'MHT - Manchester Post Sec New Wng', '', '1 Airport Rd', '', 'Manchester', 'NH', '03103-745', '42.927098', '-71.446557'),
(76481, 'Target Bedford T-2009', '603-263-0061', '220 S River Rd', '', 'Bedford', 'NH', '03110-681', '42.943270', '-71.474100'),
(7773, 'N Andover/Rte 114', '978-975-7229', '562 Turnpike Street', '', 'North Andover', 'MA', '01845-581', '42.665865', '-71.115143'),
(885, 'Andover', '978-475-7752', '14 Main Street', '', 'Andover', 'MA', '01810-370', '42.656393', '-71.140289'),
(9716, 'Concord, Loudon Road', '603-223-2395', '240 Loudon Road', '', 'Concord', 'NH', '03301-602', '43.222904', '-71.491969'),
(7960, 'Nashua Mall Power Center', '603-579-4761', '10 Coliseum Avenue', '', 'Nashua', 'NH', '03063-323', '42.765130', '-71.497440'),
(7450, 'Beverly', '978-922-0885', '29 Enon Street', '', 'Beverly', 'MA', '01915-111', '42.585366', '-70.884440'),
(14996, 'UMASS - Lowell', '', '1 Solomont Way', '', 'Lowell', 'MA', '01854-512', '42.641549', '-71.334888'),
(10278, 'Pheasant Lane Mall', '603-897-1860', '310 Daniel Webster Hwy., E281', 'E281', 'Nashua', 'NH', '03060-573', '42.700708', '-71.436142'),
(11531, 'Nashua, 611 Amherst St', '603-883-1600', '611 Amherst St.', '', 'Nashua', 'NH', '03063-101', '42.801030', '-71.537014'),
(5107, 'Target Lowell T-2480', '978-703-2020', '199 Plain St', '', 'Lowell', 'MA', '01852-513', '42.624620', '-71.318450'),
(11848, 'Beverly, 242 Elliott St', '978-927-0748', '242 Elliott St.', '', 'Beverly', 'MA', '01915-241', '42.556249', '-70.890407'),
(7658, 'Chelmsford', '978-458-2464', '101 Drum Hill Road', '', 'Chelmsford', 'MA', '01824-151', '42.623739', '-71.364310'),
(833, 'Peabody', '978-531-8224', '240 Andover Street', '', 'Peabody', 'MA', '01960-153', '42.545939', '-70.946655'),
(2765, 'North Shore Mall', '978-531-1331', '210 Andover Street, Space W 133', '', 'Peabody', 'MA', '01960-167', '42.545240', '-70.944680'),
(11757, 'Wilmington Crossing', '978-658-2541', '271 Main St., Space #253', 'Space #253', 'Wilmington', 'MA', '01887-232', '42.555543', '-71.181095'),
(8650, 'Billerica', '978-436-9180', '199 Boston Road, Unit 15', 'Unit 15', 'Billerica', 'MA', '01862-232', '42.581632', '-71.289347'),
(9269, 'Reading Walkers Brook', '781-942-8290', '24 Walkers Brook Drive', '', 'Reading', 'MA', '01867-322', '42.519991', '-71.093858'),
(7356, 'Salem-Dodge Street', '978-825-0824', '211 Washington Street', '', 'Salem', 'MA', '01970-360', '42.518951', '-70.894874'),
(7772, 'Reading', '781-942-0168', '288 Main Street', '', 'Reading', 'MA', '01867-361', '42.515659', '-71.104029'),
(15489, 'Target Woburn T-1266', '781-904-0002', '101 Commerce Way', '', 'Woburn', 'MA', '01801-100', '42.518122', '-71.135588'),
(9984, 'Woburn, Commerce Way', '781-933-4672', '99 Commerce Way', '', 'Woburn', 'MA', '01801-519', '42.517323', '-71.135712'),
(75861, 'Maine Turnpike Kennebunk North', '207-985-4234', 'maine Trnpike Northbound exit 24', '', 'Kennebunk', 'ME', '04043-702', '43.385365', '-70.542110'),
(75860, 'Kennebunk South, Maine Turnpike', '207-985-4817', 'Maine Turnpike Southbound MM 24', '', 'kennebunk', 'ME', '04043-702', '43.385365', '-70.542110'),
(7812, 'Woburn, West Cummings Park', '781-938-9305', '200 W Cummings Park, 1', '1', 'Woburn', 'MA', '01801-633', '42.498180', '-71.125908'),
(7522, 'Marblehead', '781-639-0368', '89 Pleasant Street', '', 'Marblehead', 'MA', '01945-338', '42.502632', '-70.856048'),
(13978, 'Saugus, The Shops at Saugus', '781-231-4928', '366 B Broadway', '', 'Saugus', 'MA', '01906-190', '42.488116', '-71.019400'),
(802, 'Swampscot', '781-581-9001', '1016 Paradise Road', '', 'Swampscott', 'MA', '01907-135', '42.484973', '-70.901011'),
(7269, 'Saugus', '781-233-4173', '723 Broadway', '', 'Saugus', 'MA', '01906-320', '42.478313', '-71.023173'),
(9913, 'Westford Valley Marketplace', '978-392-5926', '174 Littleton Road', '', 'Westford', 'MA', '01886-319', '42.566563', '-71.421995'),
(7279, 'Marketplace at Burlington', '781-273-6544', '84 Burlington Mall Road, Suite D', 'Suite D', 'Burlington', 'MA', '01803-453', '42.487550', '-71.202290'),
(10598, 'Bedford, Great Road', '781-275-0992', '186 Great Road', '', 'Bedford', 'MA', '01730-271', '42.489622', '-71.272350'),
(7258, 'Melrose Center', '781-662-0217', '521 Main Street', '', 'Melrose', 'MA', '02176-383', '42.455468', '-71.064841'),
(876, 'Winchester', '781-729-1626', '542 Main Street', '', 'Winchester', 'MA', '01890-291', '42.452030', '-71.136821'),
(7553, 'Lexington/Bedford Rd', '781-863-1189', '60 Bedford Street', '', 'Lexington', 'MA', '02420-433', '42.453613', '-71.233316'),
(866, 'Lexington', '781-863-8485', '1729 Massachusetts Ave', '', 'Lexington', 'MA', '02420-530', '42.447500', '-71.226705'),
(76681, 'Target Biddeford T-2166', '207-284-2510', '585 Alfred Rd', '', 'Biddeford', 'ME', '4005', '43.474469', '-70.513594'),
(7283, 'Medford - Star Market', '781-396-3630', '2151 Mystic Valley Parkway', '', 'Medford', 'MA', '02155-375', '42.417173', '-71.126646'),
(7364, 'Mass. Ave., Arlington', '781-646-9366', '1465 Massachusetts Ave', '', 'Arlington', 'MA', '02476-410', '42.425296', '-71.188507'),
(7205, 'Arlington', '781-641-2893', '327 Broadway', '', 'Arlington', 'MA', '02474-530', '42.414751', '-71.150990'),
(8988, 'Station Landing', '781-395-0660', '5 Revere Beach Pkwy., Station Landing Phase 1', 'Station Landing Phase 1', 'Medford', 'MA', '02155-515', '42.404329', '-71.081279'),
(10037, 'Tilton, Tanger Outlet', '603-286-2640', '120 Laconia Road, Suite 100', '', 'Tilton', 'NH', '03276-523', '43.457104', '-71.563661'),
(76315, 'Target Revere T-1942', '781-922-6030', '36 Furlong Dr', '', 'Revere', 'MA', '02151-400', '42.400825', '-71.001876'),
(816, 'Concord', '978-287-0183', '159 Sudbury Road', '', 'Concord', 'MA', '01742-342', '42.455669', '-71.355854'),
(15208, 'Target Everett T-1229', '617-420-0000', '1 Mystic View Rd', '', 'Everett', 'MA', '02149-242', '42.401847', '-71.069932'),
(14138, 'East Boston', '617-561-3704', '430 McClellan Highway', '', 'East Boston', 'MA', '02128-114', '42.393203', '-71.012803'),
(78032, 'BOS Term B AA Pre-Security', '617-634-6097', '440 McClellan Highway', '', 'Boston', 'MA', '02128-112', '42.393095', '-71.013054'),
(7502, 'Davis Square Plaza', '617-623-4497', '260 Elm Street', '', 'Somerville', 'MA', '02144-295', '42.395759', '-71.122297'),
(871, 'Belmont', '617-484-3213', '47 Leonard St.', '', 'Belmont', 'MA', '02478-252', '42.397256', '-71.175393'),
(7835, 'Acton, Kelly''s Corner', '978-264-1992', '411 Massachusettes Ave', '', 'Acton', 'MA', '01720-373', '42.474910', '-71.451609'),
(8873, 'Cambridge, Fresh Pond', '617-876-1070', '222 Alewife Brook Parkway', '', 'Cambridge', 'MA', '2138', '42.389322', '-71.141328'),
(2764, 'Somerville Avenue', '617-776-6783', '711-723 Somerville Ave', '', 'Somerville', 'MA', '02143-353', '42.386083', '-71.114181'),
(827, 'Shepard Post', '617-491-0442', '1662 Massachusetts Ave', '', 'Cambridge', 'MA', '02138-183', '42.381903', '-71.119934'),
(16917, 'Target Somerville T-1441', '617-766-4036', '180 Somerville Ave', '', 'Somerville', 'MA', '02143-340', '42.377651', '-71.090108'),
(75650, 'BOS - Terminal E - Food Court', '617-634-6097', 'Boston Logan Term E Food Court', '', 'East Boston', 'MA', '2128', '42.370131', '-71.019672'),
(810, 'Broadway Marketplace', '617-491-9911', '468 Broadway', '', 'Cambridge', 'MA', '02138-390', '42.373886', '-71.112950'),
(7241, '31 Church', '617-492-7870', '31 Church Street', '', 'Cambridge', 'MA', '02138-371', '42.374494', '-71.120170'),
(7538, 'Belmont/Cushing Sq', '617-489-8767', '112 Trapelo Rd', '', 'Belmont', 'MA', '02478-187', '42.380603', '-71.175129'),
(7102, 'Harvard Yard', '617-354-3726', '1380 Mass Ave', '', 'Cambridge', 'MA', '2138', '42.373456', '-71.119328'),
(861, 'Harvard Square', '617-492-4881', '36 JFK Street', '', 'Cambridge', 'MA', '02138-491', '42.372485', '-71.119452'),
(75840, 'BOS Boston/Logan Airport Term C', '617-594-3506', 'Logan Airport terminal C', '', 'Boston', 'MA', '2128', '42.366954', '-71.016337'),
(16158, 'BOS Terminal C Pier B', '617-634-6031', '300 Terminal C Gate C11', '', 'East Boston', 'MA', '2128', '42.366954', '-71.016337'),
(7436, 'Cambridgeside', '617-621-9507', '100 Cambridgeside Place, Suite E108', 'Suite E108', 'Cambridge', 'MA', '02141-221', '42.367158', '-71.076366'),
(75808, 'BOS - Terminal A Delta', '', 'Boston Logan International Airport', '', 'East Boston', 'MA', '2128', '42.364545', '-71.021569'),
(7550, 'Two Atlantic Avenue', '617-723-7819', '2 Atlantic Avenue', '', 'Boston', 'MA', '02110-391', '42.363920', '-71.050292'),
(72417, 'BOS - Terminal B - Gates 1-3', '', 'Boston Logan International Airport, Terminal A', 'Terminal A', 'East Boston', 'MA', '2128', '42.362660', '-71.017869'),
(75534, 'BOS - Gate 25', '617-938-4567', 'Gate 25', '', 'East Boston', 'MA', '2128', '42.362418', '-71.018339'),
(7338, 'Central Square', '617-354-5471', '655 Massachussets Ave', '', 'Cambridge', 'MA', '02139-333', '42.365661', '-71.103707'),
(75649, 'BOS - Terminal B - Pier B', '617-634-6097', 'Boston Logan Term B Pier A-Tampopo', '', 'East Boston', 'MA', '2128', '42.362050', '-71.019871'),
(8742, 'Cambridge Center', '617-577-7511', '6 Cambridge Center', '', 'Cambridge', 'MA', '02142-140', '42.363719', '-71.087931'),
(72208, 'Marriott Boston Cambridge', '617-494-6600', '2 Cambridge Center', '', 'Cambridge', 'MA', '02142-160', '42.362501', '-71.084694'),
(857, 'Cambridge Street', '617-227-2959', '222 Cambridge Street', '', 'Boston', 'MA', '02114-271', '42.361026', '-71.066486'),
(75637, 'Boston Long Wharf Marriott', '617-227-0800', '296 State St', '', 'Boston', 'MA', '02109-260', '42.359776', '-71.052130'),
(862, 'Fanueil Hall', '617-227-3821', '2-4 Faneuil Hall Market Place', '', 'Boston', 'MA', '02109-617', '42.359591', '-71.055841'),
(883, 'Steaming Kettle', '617-227-2284', '63-65 Court Street', '', 'Boston', 'MA', '02108-210', '42.359465', '-71.059376'),
(9463, '84 State Street', '617-523-3053', '84 State Street', '', 'Boston', 'MA', '02109-220', '42.359121', '-71.055600'),
(864, 'Charles Street', '617-227-3812', '97 Charles Street', '', 'Boston', 'MA', '02114-325', '42.358883', '-71.070565'),
(875, 'Devonshire', '617-720-2220', '240 Washington St.', '', 'Boston', 'MA', '02108-460', '42.357898', '-71.057821'),
(7535, '27 School Street', '617-227-7731', '27 School Street', '', 'Boston', 'MA', '02108-463', '42.357726', '-71.059220'),
(7805, 'One International Place', '617-737-4688', '1 International Place', '', 'Boston', 'MA', '02110-260', '42.356450', '-71.051818'),
(3773, 'Target Watertown T-1442', '', '550 Arsenal Street', '', 'Watertown', 'MA', '02472-285', '42.364217', '-71.156993'),
(7268, 'One Federal Bldg.', '617-357-6410', '1 Federal Street', '', 'Boston', 'MA', '02110-201', '42.356101', '-71.056999'),
(801, 'Starbucks Boston Common', '617-742-2664', '65-66 Beacon', '', 'Boston', 'MA', '2108', '42.356349', '-71.069312'),
(7531, '12 Winter Street', '617-542-1313', '12 Winter Street', '', 'Boston', 'MA', '02108-470', '42.355708', '-71.061027'),
(7382, 'Watertown - Mt. Auburn', '617-926-4644', '75 Mt Auburn Street', '', 'Watertown', 'MA', '02472-392', '42.366427', '-71.181086'),
(869, 'Federal Street', '617-946-0535', '75-101 Federal Street', '', 'Boston', 'MA', '02110-190', '42.355049', '-71.057263'),
(7201, '211 Congress', '617-542-4439', '211 Congress Street', '', 'Boston', 'MA', '02110-241', '42.354673', '-71.054837'),
(11684, 'Cambridge, Memorial Drive', '617-661-5817', '750 Memorial Drive', '', 'Cambridge', 'MA', '02139-461', '42.357962', '-71.115104'),
(10599, '125 Summer St.', '617-737-0250', '125 Summer Street', '', 'Boston', 'MA', '02110-161', '42.353170', '-71.057619'),
(7377, 'One Financial Center-Dewey Sq.', '617-428-0019', '1 Financial Center', '', 'Boston', 'MA', '02111-262', '42.352262', '-71.056024'),
(7564, '62 Boylston', '617-338-0067', '62 Boylston Street', '', 'Boston', 'MA', '02116-479', '42.352251', '-71.064439'),
(7686, 'Brighton/Soldiers Field', '617-782-1325', '1660-1670 Soldiers Field Rd', '', 'Brighton', 'MA', '02135-111', '42.358906', '-71.153598'),
(830, '443 Boylston Street', '617-536-7177', '443 Boylston Street', '', 'Boston', 'MA', '02116-330', '42.351504', '-71.072997'),
(807, 'City Place - Boston', '617-227-7332', '143 Stuart Street', '', 'Boston', 'MA', '02116-560', '42.351076', '-71.065945'),
(870, '165 Newbury', '617-536-5282', '165 Newbury Street', '', 'Boston', 'MA', '02116-287', '42.350805', '-71.078872'),
(7916, 'Saco', '207-286-3850', '509 Main Street', '', 'Saco', 'ME', '04072-156', '43.508877', '-70.434748'),
(78025, 'Boston DoubleTree', '617-956-7900', '821 Washington Street', '', 'Boston', 'MA', '02111-151', '42.348960', '-71.064154'),
(75830, 'Renaissance Boston Harbor Lobby', '', '636 Congress St', '', 'Boston', 'MA', '02210-280', '42.347946', '-71.039670'),
(7544, '755 Boylston St', '617-450-0310', '755 Boylston Street', '', 'Boston', 'MA', '02116-261', '42.349256', '-71.080937'),
(72111, 'George Sherman Union Bldg.', '617-353-2991', '775 Commonwealth Ave.', '', 'Boston', 'MA', '02215-140', '42.351153', '-71.108963'),
(75265, 'Manulife Financial', '617-663-3269', '601 Congress St', '', 'Boston', 'MA', '02210-280', '42.347488', '-71.040334'),
(822, '441 Stuart Street', '617-859-0703', '441 Stuart Street', '', 'Boston', 'MA', '02116-501', '42.348457', '-71.076293'),
(7652, 'Westin Hotel Copley', '617-867-0491', '10 Huntington Ave, Ste D', 'Ste D', 'Boston', 'MA', '02116-570', '42.348440', '-71.077587'),
(75912, 'Westin Boston Waterfront', '617-532-4600', '425 Summer St', '', 'Boston', 'MA', '02210-171', '42.347100', '-71.043673'),
(10155, 'Newton Corner', '617-796-3720', '259 Centre Street', '', 'Newton', 'MA', '02458-162', '42.359008', '-71.185313'),
(70015, 'Boston University-580 Commonwealth', '617-353-5450', '580 Commonwealth Ave', '', 'Boston', 'MA', '02215-252', '42.349686', '-71.100260'),
(7702, '874 Commonwealth Avenue', '617-734-3691', '874 Commonwealth Ave', '', 'Brookline', 'MA', '2215', '42.350550', '-71.114551'),
(72107, 'School of Management', '617-353-1529', '595 Commonwealth Ave', '', 'Boston', 'MA', '02215-170', '42.349331', '-71.100046'),
(872, '350 Newbury', '617-859-5751', '350 Newbury Street', '', 'Boston', 'MA', '02115-271', '42.348110', '-71.087150'),
(75513, 'Marriott Boston Copley-Mall Entrnc', '617-236-5800', '110 Huntington Ave', '', 'Boston', 'MA', '02116-578', '42.346988', '-71.079236'),
(7234, 'Mass Avenue at Havland', '617-236-4335', '147-151 Massachusetts Avenue', '', 'Boston', 'MA', '02115-260', '42.346806', '-71.087520'),
(72163, 'Boston Sheraton-Main Lobby', '617-378-6210', '39 Dalton Street', '', 'Boston', 'MA', '02199-390', '42.346573', '-71.083844'),
(824, 'Harvard Street', '617-738-8005', '473 Harvard Street', '', 'Brookline', 'MA', '02446-243', '42.347042', '-71.128464'),
(11726, 'Fenway Triangle Trilogy', '617-867-6545', '142-148 Brookline Avenue', '', 'Boston', 'MA', '02215-390', '42.344278', '-71.101407'),
(7551, 'Tremont-South End', '617-236-7879', '627 Tremont St, Retail Space #1', 'Retail Space #1', 'Boston', 'MA', '02118-164', '42.342611', '-71.074641'),
(7823, 'Brighton Village', '617-787-2430', '470 Washington St', '', 'Brighton', 'MA', '02135-267', '42.348748', '-71.159854'),
(2767, 'Huntington Plaza', '617-536-6501', '273 Huntington Ave', '', 'Boston', 'MA', '02115-450', '42.342014', '-71.086182'),
(867, 'Coolidge Corner', '617-739-3453', '277 Harvard St', '', 'Brookline', 'MA', '02446-290', '42.342587', '-71.121630'),
(75363, 'Northeastern U - Curry Student Ctr', '617-373-8860', '346 Huntington Ave', '', 'Boston', 'MA', '02115-500', '42.339585', '-71.089353'),
(7384, 'Newtonville', '617-965-5997', '16-18 Austin Street', '', 'Newtonville', 'MA', '02460-182', '42.350435', '-71.207591'),
(7224, 'Beth Israel', '617-277-2350', '364 Brookline Ave.', '', 'Boston', 'MA', '02215-540', '42.338293', '-71.106176'),
(7804, 'Childrens'' Hospital', '617-277-5202', '283 Longwood Avenue', '', 'Boston', 'MA', '02115-570', '42.337712', '-71.104718'),
(7336, 'Brookline-Washington Sq.', '617-232-5940', '1655 Beacon Street', '', 'Brookline', 'MA', '02445-450', '42.338746', '-71.136630'),
(7481, 'Brookline Village', '617-232-5063', '15 Harvard Street', '', 'Brookline', 'MA', '02445-790', '42.333719', '-71.118719'),
(16439, 'Cleveland Circle', '617-232-0119', '1948 Beacon St', '', 'Brighton', 'MA', '02135-770', '42.336080', '-71.150371'),
(76139, 'Target Dorchester T-1898', '617-602-1921', '7 Allstate Rd', '', 'Boston', 'MA', '02125-165', '42.328870', '-71.062881'),
(8741, 'Newton', '617-964-9690', '1269 Centre Street', '', 'Newton Centre', 'MA', '02459-153', '42.330258', '-71.194991'),
(811, 'Chestnut Hill', '617-738-6939', '1154-1160 Boylston Street', '', 'Chestnut Hill', 'MA', '02467-232', '42.323624', '-71.162437'),
(835, 'Waban', '617-244-0390', '474 Woodward Street', '', 'Waban', 'MA', '02468-152', '42.326420', '-71.230214'),
(7797, 'Newton Lower Falls', '617-630-9870', '2322 Washington Street', '', 'Newton', 'MA', '2462', '42.325456', '-71.256504'),
(76403, 'Target Leominster T-1965', '978-534-2914', '86 Orchard Hill Park Dr', '', 'Leominster', 'MA', '01453-702', '42.527313', '-71.713782'),
(880, 'South Brookline', '617-325-6261', '183 Grove St', '', 'South Brookline', 'MA', '2467', '42.303253', '-71.152063'),
(7270, 'Newton Upper Falls', '617-332-8839', '244 Needham Street', '', 'Newton', 'MA', '2464', '42.309391', '-71.213785'),
(8956, 'Leominster, Commercial Road', '978-840-1670', '14 Commercial Rd', '', 'Leominster', 'MA', '01453-333', '42.535070', '-71.741658'),
(7301, 'Sudbury', '978-579-9977', '513 Boston Post Road', '', 'Sudbury', 'MA', '01776-331', '42.359303', '-71.430362'),
(7808, 'West Roxbury- Roche Bros.', '617-325-4717', '1810 Centre Street', '', 'West Roxbury', 'MA', '02132-190', '42.287204', '-71.152575'),
(6849, 'Crenshaw & Airport, Torrance', '310-534-4835', '25348 Crenshaw Blvd.', '', 'Torrance', 'CA', '90505-610', '33.792659', '-118.331678'),
(75545, 'Warner Brothers Studio', '818-977-3460', '4000 Warner Blvd', '', 'Burbank', 'CA', '91522-000', '34.150500', '-118.340065');
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
Right.
I tried running this in an apache docker-container, and a mysql db in another docker-container. I got a couple of suggestions as to the possible errors. Although I believe suggestion 2-4 are the most likely to help you.
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.3.min.js"></script>
Try:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
coffee.php connects correctly with the database. You can do this by looking directly at the PHP-output (http://localhost/coffee.php). I had an issue with the uppercase-letters in the sql on line 3 of coffee.php. While MySQL is case insensitive with regards to table-names, I believe PHP's $db->query(); is. Regardless I would stay away from uppercase table names.
For me I just did:$sql = "SELECT * FROM coffeeshops WHERE City='Boston'";
The last thing I would recommend you to check is the JSON-encoding and -decoding. json_decode();, tend not to throw errors when fed incorrectly formated JSON.
Make sure that the getJSON function actually returns the correct JSON. I used http://localhost/coffee.php as the endpoint for the getJSON request, instead of just coffee.php.
If none of these help you, then please provide us with the returned output of the coffee.php file and with a console.log(); of the data that was fetched by the getJSON.
This is the output I got (I had to add my own mug.png file): Screenshot of output on listing43.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With