This section describes how to obtain the longitudes and latitudes of places. A maximum of 10 records can be returned.
sites: search result, which is a Site[] array of up to 10 records. For details about the array, please refer to Parameters.
<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 = {
address: '57,RUE DU CAPITAINE PICAVET,LEERS,LEERS,NORD,HAUTS-DE-FRANCE,France'
};
// Call the forward geocoding API. In the API, result indicates the search result and status indicates the search status.
siteService.geocode(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>