if (navigator.geolocation){ navigator.geolocation.getCurrentPosition(zoomToLocation, locationError); }
function zoomToLocation(location) { var pt = new esri.geometry.Point(location.coords.longitude, location.coords.latitude); var outSR = new esri.SpatialReference({ wkid: 3008}); gsvc.project([ pt ], outSR, function(projectedPoints) { pt = projectedPoints[0]; map.centerAndZoom(pt, 8); }); }
Solved! Go to Solution.
We are trying to use GPS location in a map with services in wkid 3008 using this code:if (navigator.geolocation){ navigator.geolocation.getCurrentPosition(zoomToLocation, locationError); }function zoomToLocation(location) { var pt = new esri.geometry.Point(location.coords.longitude, location.coords.latitude); var outSR = new esri.SpatialReference({ wkid: 3008}); gsvc.project([ pt ], outSR, function(projectedPoints) { pt = projectedPoints[0]; map.centerAndZoom(pt, 8); }); }
But we don't get the expected result, map loads fine but when using position maps zooms in to a out of bounds location.
What are we missing?
We are trying to use GPS location in a map with services in wkid 3008 using this code:if (navigator.geolocation){ navigator.geolocation.getCurrentPosition(zoomToLocation, locationError); }function zoomToLocation(location) { var pt = new esri.geometry.Point(location.coords.longitude, location.coords.latitude); var outSR = new esri.SpatialReference({ wkid: 3008}); gsvc.project([ pt ], outSR, function(projectedPoints) { pt = projectedPoints[0]; map.centerAndZoom(pt, 8); }); }
But we don't get the expected result, map loads fine but when using position maps zooms in to a out of bounds location.
What are we missing?
function zoomToLocation(location) {
var pt = new esri.geometry.Point(location.coords.longitude, location.coords.latitude, new esri.SpatialReference({ wkid: 4326 }));
var outSR = new esri.SpatialReference({ wkid: 3008});
gsvc.project([ pt ], outSR, function(projectedPoints) {
pt = projectedPoints[0];
map.centerAndZoom(pt, 8);
});
}
function zoomToLocation(location) { // use this if basemap is WGS84 --- var pt = esri.geometry.geographicToWebMercator(new esri.geometry.Point(location.coords.longitude, location.coords.latitude)); //otherwise, use this stuff below - basically we make a new point with the geolocated coordinates and reproject it, but to do so, you make the point //first and specify it's originating spatial reference so then you can reproject it to your own wkid var pt = new esri.geometry.Point(location.coords.longitude, location.coords.latitude, new esri.SpatialReference({wkid: 4236})); //don't forget to specify the originating wkid (in this case from the GPS/Geolocation) var outSR = new esri.SpatialReference({ wkid: 3735}); gsvc.project([ pt ], outSR, function(projectedPoints) {[INDENT] pt = projectedPoints[0];[/INDENT] [INDENT] map.centerAndZoom(pt, 8);[/INDENT] [INDENT] //add graphic at current location - if graphic exists just move it[/INDENT] [INDENT] if(!currGraphic){ var symbol = new esri.symbol.PictureMarkerSymbol("images/i_runningman.png",40,40); currGraphic = new esri.Graphic(pt,symbol); map.graphics.add(currGraphic); } else{ currGraphic.setGeometry(pt); }[/INDENT] }); }