-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstore_map.html
95 lines (89 loc) · 1.99 KB
/
store_map.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<!DOCTYPE html>
<html>
<head>
<title>Simple Map</title>
<meta name="viewport" content="initial-scale=1.0">
<meta http-equiv="Access-Control-Allow-Origin" content="*"/>
<meta charset="utf-8">
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 80%;
width: 80%;
margin: 0 auto;
margin-top: 40px;
}
#button {
height: 50px;
width: 80px;
background-color: dodgerblue;
}
label {
margin-left: 10%;
}
</style>
</head>
<body>
<label>Store Postcode: </label>
<input name="postcode" id="codepost" type="text">
<button id="button">Search</button>
<div id="map"></div>
<script>
var map;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -26.715, lng: 153.064},
zoom: 8
});
}
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#button").click(function(){
try {
marker.setMap(null);
} catch(err) {
//do nothing
console.log("not number");
}
var storecode = document.getElementById("codepost").value;
console.log(storecode);
$.ajax( {
url: "http://localhost:8080/getlocation?postcode=" + storecode,
method: "get",
dataType: "json"
})
.done(function(msg) {
var result = msg.Name;
var Lat = msg.Lat;
var Lon = msg.Lon;
console.log(result);
console.log(Lat);
console.log(Lon);
marker = new google.maps.Marker({
map: map,
position: {lat: parseFloat(Lat), lng: parseFloat(Lon)},
title: result
});
map.setCenter(marker.getPosition());
})
.fail(function(error){
alert("Error input. Default store will be selected. ");
marker = new google.maps.Marker({
map: map,
position: {lat: parseFloat(Lat), lng: parseFloat(Lon)},
title: result
});
});
});
});
</script>
<script src="https://maps.googleapis.com/maps/api/js?
key=AIzaSyCO3hE4bE7WV7mGuXL4kn9caoWI44tD8Ic&callback=initMap" async defer></script>
</body>
</html>