SebastianD

How does Geolocation on a custom ArcGISTiledMapServiceLayer work?!

Discussion created by SebastianD on Feb 17, 2012
Latest reply on Apr 13, 2012 by DublinOhio
Hi all,

i have a custom ArcGISTiledMapServiceLayer and i like to use the geolocation API on it. When i test the function (my current position is in the map!) it shows and zoom to a location point
which is NEVER in my mapextent. My spatialReference is wkid: 32640! Did i neet to convert the coordinates like this post: convert coordinates) ?

function init() {
    initialExtent = new esri.geometry.Extent({ "xmin": 351177.108232252, "ymin": 2824081.4592078, "xmax": 438159.053029475, "ymax": 2878255.00505489, "spatialReference": { "wkid": 32640} });    
    map = new esri.Map("Maparea", { extent: initialExtent});
    LayerTiledMap1 = new esri.layers.ArcGISTiledMapServiceLayer("http://www.rakmaps.com/ArcGIS/rest/services/RAK_Businessmap/MapServer", { id: "imageMap" });
    map.addLayer(LayerTiledMap1);
}


Function for geolocation:
function getGeolocation() {       
    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition(setLocation, locationError);
    } else {
        alert("Geolocation not supported on this device.");
    }
}
function setLocation(location) {
   var pt = esri.geometry.geographicToWebMercator(new esri.geometry.Point(location.coords.longitude, location.coords.latitude));
   // doesen't work, too: var pt = esri.geometry.geographicToWebMercator(new esri.geometry.Point(location.coords.longitude, location.coords.latitude, new esri.SpatialReference({wkid: 32640})));
  
 if (!posGraphic) {
        addGraphic(pt);
   } else { 
        posGraphic.setGeometry(pt);
   }
    map.centerAndZoom(pt, 3);
}
function addGraphic(pt) {
    var symbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE, 30,
          new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID,
          new dojo.Color([210, 105, 30, 0.5]), 8),
          new dojo.Color([210, 105, 30, 0.9])
        );
    posGraphic = new esri.Graphic(pt, symbol);
    map.graphics.add(posGraphic);
}




Appreciate the help!

Outcomes