Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get points from MySQL #3

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
node_modules/
package-lock.json
6 changes: 6 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"host": "localhost",
"user": "maps",
"password": "maps",
"database": "maps"
}
15 changes: 15 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
const mysql = require('mysql');
const express = require('express');
const config = require('./config.json');
const app = express();

const con = mysql.createConnection(config);

con.connect(function(err) {
if (err) throw err;
con.query("SELECT * FROM points", function (err, result, fields) {
if (err) throw err;
console.log(result);
app.get('/points', function (req, res) {
res.send(result)
})
});
});

app.use(express.static('public'));

app.listen(3000, function () {
Expand Down
13 changes: 13 additions & 0 deletions maps.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
DROP TABLE IF EXISTS `points`;
CREATE TABLE `points` (
`id` int(11) NOT NULL,
`name` varchar(16) NOT NULL,
`lat` float NOT NULL,
`lng` float NOT NULL,
`info` varchar(256) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

LOCK TABLES `points` WRITE;
INSERT INTO `points` VALUES (1,'WroTest',51,17,'test test test');
UNLOCK TABLES;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
},
"homepage": "https://github.com/dynak-net/super-simple-maps#readme",
"dependencies": {
"express": "^4.15.3"
"express": "^4.15.3",
"mysql": "^2.13.0"
}
}
3 changes: 2 additions & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
<div id="map" style="width: 100%; height: 100%;"></div>
<script src="js/data.js"> </script>
<script src="js/map.js"> </script>
<script async defer src="https://maps.googleapis.com/maps/api/js?v=3&key=YOUR_API_KEY&callback=initMap"> </script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?v=3&key=AIzaSyCeKf-4vZrm7FiTagQTTG8yysA5vwSWyd4&callback=initMap"> </script>
<!--script src="js/markerclusterer.js"> </script-->
</body>
</html>
5 changes: 4 additions & 1 deletion public/js/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ function initMap() {
setMarkers(map);
}

function setMarkers(map) {
async function setMarkers(map) {
var infoWindow = new google.maps.InfoWindow();
let response = await fetch('/points');
let json = await response.json();
console.log(json);
for (var i = 0; i < myPoints.length; i++) {
var myPoint = myPoints[i];
var marker = new google.maps.Marker({
Expand Down