This section describes how to obtain places corresponding to the specified longitudes and latitudes. A maximum of 11 records can be returned.
sites: search result, which is a Site[] array of up to 11 records. For details about the array, please refer to Parameters. Note that the Site array does not contain the POI information.
<body>
<div id="map"></div>
<script>
var markers = [];
var map;
var mapOptions = {};
function initMap() {
mapOptions.center = {lat: 48.856613, lng: 2.352222};
mapOptions.zoom = 8;
map = new HWMapJsSDK.HWMap(document.getElementById('map'), mapOptions);
var siteService
// Initialize the HWSiteService object.
siteService = new HWMapJsSDK.HWSiteService();
// Construct a request.
var request = {
location: {
lat: 18.0527,
lng: 77.2155
}
};
// Call the reverse geocoding API. In the API, result indicates the search result and status indicates the search status.
siteService.reverseGeocode(request, function (result, status) {
if (status == '0') {
const res = result && result.sites && result.sites[0].location
if (res) {
// Add a marker.
var marker = new HWMapJsSDK.HWMarker({
map: map,
position: {lat: res.lat, lng: res.lng},
label: result.sites[0].name
});
markers.push(marker);
// Set the map center.
map.setCenter({lat: res.lat, lng: res.lng})
}
}
});
}
</script>
</body>