Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
102 lines (83 sloc) 4.37 KB
<!DOCTYPE html>
<title>Reverse Geocode with Services Module - Azure Maps Web SDK Samples</title>
<meta charset="utf-8" />
<meta http-equiv="x-ua-compatible" content="IE=Edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<meta name="description" content="This sample shows how to use the Services module for Azure Maps to reverse geocode a coordinate." />
<meta name="keywords" content="map, gis, API, SDK, services, module, search, reverse, geocode, geocoding, address, addresses" />
<meta name="author" content="Microsoft Azure Maps" />
<!-- Add references to the Azure Maps Map control JavaScript and CSS files. -->
<link rel="stylesheet" href="" type="text/css" />
<script src=""></script>
<!-- Add a reference to the Azure Maps Services Module JavaScript file. -->
<script src=""></script>
<script type='text/javascript'>
var map, searchURL, popup;
function GetMap() {
//Initialize a map instance.
map = new atlas.Map('myMap', {
center: [-122.335, 47.608],
zoom: 15,
view: 'Auto',
//Add your Azure Maps subscription key to the map SDK. Get an Azure Maps key at
authOptions: {
authType: 'subscriptionKey',
subscriptionKey: '<Your Azure Maps Key>'
//Use SubscriptionKeyCredential with a subscription key
var subscriptionKeyCredential = new atlas.service.SubscriptionKeyCredential(atlas.getSubscriptionKey());
//Use subscriptionKeyCredential to create a pipeline
var pipeline = atlas.service.MapsURL.newPipeline(subscriptionKeyCredential, {
retryOptions: { maxTries: 4 }, // Retry options
//Create an instance of the SearchURL client.
searchURL = new atlas.service.SearchURL(pipeline);
//Wait until the map resources are ready.'ready', function () {
//Update the style of mouse cursor to a crosshair.
map.getCanvasContainer().style.cursor = 'crosshair';
//Create a popup but leave it closed so we can update it and display it later.
popup = new atlas.Popup({
position: [0, 0]
//Add a click event to the map.'click', mapClicked);
function mapClicked(e) {
//Execute the reverse address search query and open a popup once a response is received.
searchURL.searchAddressReverse(atlas.service.Aborter.timeout(3000), e.position, {
view: 'Auto'
}).then(results => {
//Get the results in GeoJSON format.
var data = results.geojson.getFeatures();
var content = '<div style="padding:10px">';
if (data.features.length > 0 && data.features[0].properties && data.features[0].properties.address && data.features[0].properties.address.freeformAddress) {
content += data.features[0].properties.address.freeformAddress;
} else {
content += 'No address for that location!';
content += '</div>';
//Set the popup options.
position: e.position,
content: content
//Open the popup.;
<body onload="GetMap()">
<div id="myMap" style="position:relative;width:100%;min-width:290px;height:600px;"></div>
<fieldset style="width:calc(100% - 30px);min-width:290px;margin-top:10px;">
<legend>Reverse Geocode with Services Module</legend>
This sample shows how to use the Services module for Azure Maps to reverse geocode a coordinate.
Click on any location on the map and a coordinate of where you clicked will be used to perform a reverse geocode.
You can’t perform that action at this time.