GPS locator not working for Election Polling Place ver 2.2

1092
10
Jump to solution
04-23-2012 12:42 PM
BrandonVan_Horn
Occasional Contributor
Hello I am trying to get the GPS locator working on this application. I keep getting "You are currently outside the supported area" dialog box. Everything but this is working. Are their any settings that have to be set to use this functionality? Thanks for your help.

Brandon
0 Kudos
1 Solution

Accepted Solutions
BrandonVan_Horn
Occasional Contributor
I figured it out. The GPS locater was returning the location value in latitude and longitude. Therefor the location value did not fall with in the full extent value. That is because the values that are being used for the full extent are in Web Mercator Projection. Any the code to fix this is below.

Class: utls.js


navigator.geolocation.getCurrentPosition(
  function (position) {
      ShowProgressIndicator();
      mapPoint = esri.geometry.geographicToWebMercator(new esri.geometry.Point(position.coords.longitude, position.coords.latitude, new esri.SpatialReference({ wkid: 4326 }))); //Changed this line to include "esri.geometry.geographicToWebMercator("
      var graphicCollection = new esri.geometry.Multipoint(new esri.SpatialReference({ wkid: 102100 })); //changed wkid: 102100 Web Mercator
      graphicCollection.addPoint(mapPoint); //graphicCollection.addPoint(mapPoint)
      geometryService.project([graphicCollection], map.spatialReference, function (newPointCollection) {
          for (var bMap = 0; bMap < baseMapLayers.length; bMap++) {
              if (map.getLayer(baseMapLayers[bMap].Key).visible) {
                  var bmap = baseMapLayers[bMap].Key;
              }
          }
          if (!map.getLayer(bmap).fullExtent.contains(mapPoint)) {
              map.infoWindow.hide();
              selectedPollPoint = null;
              pollPoint = null;
              mapPoint = null;
              ClearSelection();
              map.getLayer(tempGraphicsLayerId).clear();
              map.getLayer(precinctLayerId).clear();
              map.getLayer(routeGraphicsLayerId).clear();
              map.getLayer(highlightPollLayerId).clear();
              HideProgressIndicator();
              if (!isMobileDevice) {
                  var imgToggle = dojo.byId('imgToggleResults');
                  if (imgToggle.getAttribute("state") == "maximized") {
                      imgToggle.setAttribute("state", "minimized");
                      WipeOutResults();
                      dojo.byId('imgToggleResults').src = "images/up.png";
                  }
              }
              ShowInfoDetailsView();
              alert(messages.getElementsByTagName("geoLocation")[0].childNodes[0].nodeValue);
              return;
          } else { //Added the else statement.
              mapPoint = newPointCollection[0].getPoint(0);
              LocateAddressOnMap(false);
          }
      });
  },
  function (error) {
      HideProgressIndicator();
      switch (error.code) {
          case error.TIMEOUT:
              alert(messages.getElementsByTagName("geolocationTimeout")[0].childNodes[0].nodeValue);
              break;
          case error.POSITION_UNAVAILABLE:
              alert(messages.getElementsByTagName("geolocationPositionUnavailable")[0].childNodes[0].nodeValue);
              break;
          case error.PERMISSION_DENIED:
              alert(messages.getElementsByTagName("geolocationPermissionDenied")[0].childNodes[0].nodeValue);
              break;
          case error.UNKNOWN_ERROR:
              alert(messages.getElementsByTagName("geolocationUnKnownError")[0].childNodes[0].nodeValue);
              break;
      }
  }, { timeout: 10000 });
}


Hope this helps someone else out. Have a great day.

Brandon

View solution in original post

0 Kudos
10 Replies
BrandonVan_Horn
Occasional Contributor
I figured it out. The GPS locater was returning the location value in latitude and longitude. Therefor the location value did not fall with in the full extent value. That is because the values that are being used for the full extent are in Web Mercator Projection. Any the code to fix this is below.

Class: utls.js


navigator.geolocation.getCurrentPosition(
  function (position) {
      ShowProgressIndicator();
      mapPoint = esri.geometry.geographicToWebMercator(new esri.geometry.Point(position.coords.longitude, position.coords.latitude, new esri.SpatialReference({ wkid: 4326 }))); //Changed this line to include "esri.geometry.geographicToWebMercator("
      var graphicCollection = new esri.geometry.Multipoint(new esri.SpatialReference({ wkid: 102100 })); //changed wkid: 102100 Web Mercator
      graphicCollection.addPoint(mapPoint); //graphicCollection.addPoint(mapPoint)
      geometryService.project([graphicCollection], map.spatialReference, function (newPointCollection) {
          for (var bMap = 0; bMap < baseMapLayers.length; bMap++) {
              if (map.getLayer(baseMapLayers[bMap].Key).visible) {
                  var bmap = baseMapLayers[bMap].Key;
              }
          }
          if (!map.getLayer(bmap).fullExtent.contains(mapPoint)) {
              map.infoWindow.hide();
              selectedPollPoint = null;
              pollPoint = null;
              mapPoint = null;
              ClearSelection();
              map.getLayer(tempGraphicsLayerId).clear();
              map.getLayer(precinctLayerId).clear();
              map.getLayer(routeGraphicsLayerId).clear();
              map.getLayer(highlightPollLayerId).clear();
              HideProgressIndicator();
              if (!isMobileDevice) {
                  var imgToggle = dojo.byId('imgToggleResults');
                  if (imgToggle.getAttribute("state") == "maximized") {
                      imgToggle.setAttribute("state", "minimized");
                      WipeOutResults();
                      dojo.byId('imgToggleResults').src = "images/up.png";
                  }
              }
              ShowInfoDetailsView();
              alert(messages.getElementsByTagName("geoLocation")[0].childNodes[0].nodeValue);
              return;
          } else { //Added the else statement.
              mapPoint = newPointCollection[0].getPoint(0);
              LocateAddressOnMap(false);
          }
      });
  },
  function (error) {
      HideProgressIndicator();
      switch (error.code) {
          case error.TIMEOUT:
              alert(messages.getElementsByTagName("geolocationTimeout")[0].childNodes[0].nodeValue);
              break;
          case error.POSITION_UNAVAILABLE:
              alert(messages.getElementsByTagName("geolocationPositionUnavailable")[0].childNodes[0].nodeValue);
              break;
          case error.PERMISSION_DENIED:
              alert(messages.getElementsByTagName("geolocationPermissionDenied")[0].childNodes[0].nodeValue);
              break;
          case error.UNKNOWN_ERROR:
              alert(messages.getElementsByTagName("geolocationUnKnownError")[0].childNodes[0].nodeValue);
              break;
      }
  }, { timeout: 10000 });
}


Hope this helps someone else out. Have a great day.

Brandon
0 Kudos
AllisonMuise
New Contributor III
Thank you for pointing this out, Brandon.

We will definitely look into resolving this.

-Allison Muise

Product Engineer
ArcGIS for Local Government
0 Kudos
DavidGenaway
New Contributor II

      mapPoint = esri.geometry.geographicToWebMercator(new esri.geometry.Point(position.coords.longitude, position.coords.latitude, new esri.SpatialReference({ wkid: 4326 }))); //Changed this line to include "esri.geometry.geographicToWebMercator("
var graphicCollection = new esri.geometry.Multipoint(new esri.SpatialReference({ wkid: 102100 })); //changed wkid: 102100 Web Mercator
     



Thanks, these lines worked for me in the Park Finder app for the geolocation.
0 Kudos
JordanBrod
New Contributor III
I have tried this method and while it does make the button work it seems to misplace the gps or computer location by half a mile or so from where one is actually located, any idea what could be causing this?
0 Kudos
BrandonVan_Horn
Occasional Contributor
Are you using a GPS?
The GPS on the phone\ tablets usually work really well. Within some acceptable tolerances.

..or are you trying to locate the computer?
From what I can figure is the computer location is based on where the IP address is registered. This usually gets you within a town\ city but not always.
Like a zip code

Information link on the different type of locations
http://mobile.tutsplus.com/tutorials/mobile-web-apps/html5-geolocation/

Good Luck,
Brandon
0 Kudos
JordanBrod
New Contributor III
The GPS on a phone had the greatest inaccuracy the computer just puts us across the street, the gps put us in another part of town.  Is your main data in the localgovernment.gdb in your local coordinate system or are you putting it into the web mercator projection?
0 Kudos
BrandonVan_Horn
Occasional Contributor
Well we have customized the code to use our SQL database. This is in WebMercator.
0 Kudos
JordanBrod
New Contributor III
All of our data in our sql database is in the State Plane system then all of our webmaps are in the Web Mercator Aux projection(the form the come in the templates).  So I don't know if the cause of the inaccuracy is because of this or if something else is going on.  Could also be a bad time of day for taking GPS, but I wouldn't expect the phone to throw us this far off.
0 Kudos
BrandonVan_Horn
Occasional Contributor
Sorry I don't know about that. I just checked my computer and my phone at the same site and I am experiencing the opposite of what you are. My GPS is approx 25- 50 feet away from my location. While my computer is 2-3 miles away. Our production database is in State Plane, then we reproject to WebM for our online database. Our services are pointing to the Web database. I don't think this has anything to do with it though. Sorry I cant help you more.
0 Kudos