<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
<link rel="stylesheet" href="http://js.arcgis.com/3.10/js/dojo/dijit/themes/claro/claro.css">
<title>Geocoder Widget</title>
<link rel="stylesheet" href="http://js.arcgis.com/3.10/js/esri/css/esri.css">
<style>
html, body, #map {
height:100%;
width:100%;
margin:0;
padding:0;
}
body {
background-color:#FFF;
overflow:hidden;
font-family:"Trebuchet MS";
}
#searchbox {
display: block;
position: absolute;
z-index: 2;
top: 20px;
left: 75px;
}
</style>
<script src="http://js.arcgis.com/3.9/"></script>
<script>
var map;
var geocoder;
require([
"esri/map", "esri/dijit/Geocoder", "esri/SpatialReference", "dijit/form/TextBox", "dojo/parser",
"esri/tasks/locator", "dojo/on", "dojo/dom", "dijit/registry", "dijit/form/Button" ,"dojo/domReady!"
], function(
Map, Geocoder, SpatialReference, TextBox, parser, Locator, on, dom, registry
) {
parser.parse();
var locatorUrl = "http://serverapps101.esri.com/arcgis/rest/services/MGRS/GeocodeServer";
var Gridlocator = new Locator(locatorUrl);
var locator = new Locator("http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer");
var spatialReference = new SpatialReference({wkid:4326});
map = new Map("map",{
basemap: "topo",
center: [-117.19,34.05], // lon, lat
zoom: 13,
spatialReference: spatialReference
});
var GridTextBox = new TextBox({
placeHolder: "18SUJ23480647",
value:"18SUJ23480647"
},"GridTextBoxDiv");
on(registry.byId("grid"), "click", setgrid);
function setgrid (){
var GridPoint = registry.byId("GridTextBoxDiv").get("value");
var gridnmb = {MGRS:GridPoint};
Gridlocator.addressToLocations(gridnmb);
map.graphics.clear();
}
Gridlocator.on("address-to-locations-complete", locateMeGridAddress);
function locateMeGridAddress(evt){
var FoundPointAr = evt.addresses;
var FoundPoint = FoundPointAr[0];
var LocPoint = FoundPoint.location;
map.centerAndZoom(LocPoint);
map.graphics.clear();
}
});
</script>
</head>
<body class="claro">
<div id="map">
<div id="searchbox"><input id="GridTextBoxDiv"/><button id="grid" data-dojo-type="dijit.form.Button" type="button" data-dojo-attach-point="button">Get Location</button> </div>
</div>
</body>
</html>