This is from a page I set up using ESRI's Javascript API. Basically I'm letting the user search for an address, then confirming the address with a mouse click. Then grabbing coordinates on the mouse click and passing them to some text boxes on my page. I then have some code behind that moves the coordinates to a SQL table.
script src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=1.6" type="text/javascript"script
script type="text/javascript"
dojo.require("esri.map");
dojo.require("esri.tasks.geometry");
var map = null;
var gsvc = null;
var pt = null;
var findTask, findParams;
function initialize() {
map = new esri.Map("map");
var dynamicMapServiceLayer = new esri.layers.ArcGISDynamicMapServiceLayer("http://service name");
map.addLayer(dynamicMapServiceLayer);
gsvc = new esri.tasks.GeometryService("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
dojo.connect(map, "onClick", projectToWebMercator);
//Create Find Task using the URL of the map service to search
findTask = new esri.tasks.FindTask("http://service name");
//Create the find parameters
findParams = new esri.tasks.FindParameters();
findParams.returnGeometry = true;
findParams.layerIds = [10];
findParams.searchFields = ["ADDRESS"];
}
function projectToWebMercator(evt) {
map.graphics.clear();
var point = evt.mapPoint;
var symbol = new esri.symbol.SimpleMarkerSymbol().setStyle(esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE);
var graphic = new esri.Graphic(point, symbol);
var outSR = new esri.SpatialReference({ wkid: 2264});
map.graphics.add(graphic);
gsvc.project([ graphic ], outSR, function(features) {
pt = features[0].geometry;
Form1.TextBox1.value = pt.x
Form1.TextBox2.value = pt.y
//graphic.setInfoTemplate(new esri.InfoTemplate("Coordinates",
//"<p> X: " + pt.x +
//"<br/> Y: " + pt.y +
//"</p>" +
//"<input type='button' value='Convert back to LatLong' onclick='projectToLatLong();' />" +
//"<div id='latlong'></div>"));
//map.infoWindow
//.setTitle(graphic.getTitle())
//.setContent(graphic.getContent())
//.show(evt.screenPoint, map.getInfoWindowAnchor(evt.screenPoint));
});
}
function projectToLatLong() {
var symbol = new esri.symbol.SimpleMarkerSymbol();
var graphic = new esri.Graphic(pt, symbol);
var outSR = new esri.SpatialReference({ wkid: 4326});
gsvc.project([ graphic ], outSR, function(features) {
pt = features[0].geometry;
dojo.byId("latlong").innerHTML = " Latitude = " + pt.y + "<br/> Longitude = " + pt.x;
});
}
function doFind() {
//Set the search text to the value in the box
findParams.searchText = dojo.byId("ownerName").value;
findTask.execute(findParams,showResults);
}
function showResults(results) {
//find results return an array of findResult.
map.graphics.clear();
var dataForGrid = [];
for (var i = 0, il = results.length; i < il; i++) {
var curFeature = results[i];
var graphic = curFeature.feature;
var layerName = curFeature.layerName;
var layerId = curFeature.layerId;
var foundFieldName = curFeature.foundFieldName;
var foundFieldValue = graphic.attributes[foundFieldName];
var attValues = [layerName, layerId, foundFieldName, foundFieldValue];
dataForGrid.push(attValues);
switch (graphic.geometry.type) {
case "point":
var symbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE, 10, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 0, 0]), 1), new dojo.Color([0, 255, 0, 0.25]));
break;
case "polyline":
var symbol = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASH, new dojo.Color([255, 0, 0]), 1);
break;
case "polygon":
var symbol = new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_NONE, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_DASHDOT, new dojo.Color([255, 0, 0]), 2), new dojo.Color([255, 255, 0, 0.25]));
break;
}
graphic.setSymbol(symbol);
map.graphics.add(graphic);
var pt = graphic.geometry
var factor = 50; //some factor for converting point to extent
var extent = new esri.geometry.Extent(pt.x - factor, pt.y - factor, pt.x + factor, pt.y + factor, pt.SpatialReference);
map.setExtent(extent.expand(2));
}
}
dojo.addOnLoad(initialize);
I basically started with this sample and went from there.
http://resources.esri.com/help/9.3/arcgisserver/apis/javascript/arcgis/help/jssamples_start.htm
Maybe not the whole answer, but hopefully a pointer in the right direction.