-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlearning_mapbox.html
More file actions
66 lines (55 loc) · 2.08 KB
/
learning_mapbox.html
File metadata and controls
66 lines (55 loc) · 2.08 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Mapbox</title>
<link href="https://api.mapbox.com/mapbox-gl-js/v2.10.0/mapbox-gl.css" rel="stylesheet">
<style>
#map{
width: 100%;
height: 800px;
}
</style>
</head>
<body>
<div id="map"></div>
<script src="js/mapbox-geocoder-utils.js"></script>
<script src="https://api.mapbox.com/mapbox-gl-js/v2.10.0/mapbox-gl.js"></script>
<script>
const key = "pk.eyJ1IjoicmlsZXlrNjQ2IiwiYSI6ImNsOW44NTZoYTAzMHEzbm16cWVzMnVjaHYifQ.oZZ9VdLhACfrDJu7rtPWNA";
mapboxgl.accessToken = key;
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v9',
//TODO: Set your own zoom and center
zoom: 10,
center: [-75.68237215762277,39.17045120281665]
});
//TODO: Set zoom on your own with a map.setZoom call in your console
/*map.setZoom(130)*/
//TODO: Add your own marker to where we've aligned your map so far
let marker = new mapboxgl.Marker()
.setLngLat([-75.68237215762277,39.17045120281665])
.addTo(map);
//TODO: Use the geocode method to add a 2nd marker and popup to your map, then center your map over it
let popup = new mapboxgl.Popup()
.setLngLat([-75.68237215762277,39.17045120281665])
.setHTML("<p>Our house</p>")
.addTo(map)
//TODO: Try a reverse geocode yourself and see what address you get back for your coordinates - remember to send up a {lng: <lng>, lat: <lat>} object
geocode("2041 Dinahs Corner Rd", key).then(function(result){
console.log(result)
let marker2 = new mapboxgl.Marker()
.setLngLat(result)
.addTo(map)
let popup2 = new mapboxgl.Popup()
.setLngLat(result)
.setHTML("<p>Ann's house</p>")
.addTo(map)
})
reverseGeocode({lng:-75.68237215762277, lAT: 39.17045120281665}, key).then(function (result) {
alert("heres the result: || ${result}")
})
</script>
</body>
</html>