Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
64 lines (53 sloc) 2.13 KB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Reverse Geocode</title>
<style>html,body{height:100%;}body{padding:0;margin:0;}h1{padding:0;margin:0;font-size:50%;}#geocode{font-size: 120%;}</style>
</head>
<body>
<!-- MAP[START] -->
<h1>Reverse Geocode</h1>
<div id="geocode">ReverseGeocode:data</div>
<div id="myMap" style='width:60%;height:70%;float:left;'></div>
<!-- MAP[END] -->
<script src='https://www.bing.com/api/maps/mapcontrol?callback=GetMap&key=[ *** YOUR MY KEY *** ]' async defer></script>
<script src="../js/BmapQuery.js"></script>
<script>
//****************************************************************************************
// BingMaps&BmapQuery
//****************************************************************************************
//Init
function GetMap(){
//------------------------------------------------------------------------
//1. Instance
//------------------------------------------------------------------------
const map = new Bmap("#myMap");
//------------------------------------------------------------------------
//2. Display Map
// startMap(lat, lon, "MapType", Zoom[1~20]);
// MapType:[load, aerial,canvasDark,canvasLight,birdseye,grayscale,streetside]
//--------------------------------------------------
map.startMap(47.6149, -122.1941, "load", 13);
//----------------------------------------------------
//3. Get ReverseGeocode(2 patterns)
// reverseGeocode(location,callback);
//----------------------------------------------------
//A. Set location data for BingMaps
const location = map.setLocation(47.6130, -122.1945);
//const location = map.getCenter(); //MapCenter
map.reverseGeocode(location, function(data){
console.log(data);
document.querySelector("#geocode").innerHTML=data;
});
//B. Get ReverseGeocode of click location
map.onGeocode("click", function(clickPoint){
map.reverseGeocode(clickPoint.location, function(data){
console.log(data);
document.querySelector("#geocode").innerHTML=data;
});
});
}
</script>
</body>
</html>