Select to view content in your preferred language

Flex mobile geolocation

2575
16
11-17-2011 04:56 AM
deleted-user-NnRwwd8ols89
Deactivated User
Hi, I've developed a mobile application using the flex api, but the geolocation doesn't seem to be working on iOS devices, but it does on android.

I've just taken the code from the ESRI mobile web map sample provided with the api for geolocation, but iOS devices do t seem to like it! I've checked the device settings, and tried it on a few devices, but no luck, whereas on android it works fine

Anyone know anything about this!?

Thanks
Ben
Tags (2)
0 Kudos
16 Replies
ReneRubalcava
Esri Frequent Contributor
Can you use the flash debugger to verify that Geolocation.isSupported==true on your device?
0 Kudos
AaronNash
Deactivated User
can you post your code?
0 Kudos
deleted-user-NnRwwd8ols89
Deactivated User
hey, thanks for the replies, yes i've written a trace() into the following if statement:

            protected function myMap_loadHandler(event:MapEvent):void
            {
                if (Geolocation.isSupported)
                {trace("geo loop begin");
                    geo = new Geolocation;
                    if (!geo.muted) // check if Geolocation is not disabled on the device
                    {trace("geo on");
                        zoomToCurrentLocationImg.source = m_gpsA;
                        zoomToCurrentLocationImg.visible = true;
                    }
                }
            }

i get the "geo loop begin" trace but not the "geo on", i've checked the device settings and geolocation works fine in all other apps.

any ideas?! do others have this working?

thanks
Ben
0 Kudos
RajendraShelar
Deactivated User
call below function on view activate...

protected function ShowGPSLocation():void
   {

if(Geolocation.isSupported){
     lblGPSStatus.text="Locating you!...."
     geo= new Geolocation();
    
     if(geo.muted){
      Alert.show("Hey, turn on your GPS please");
     }
    
     geo.addEventListener(GeolocationEvent.UPDATE, handleLocationRequest);     
    }
    else
    {
     Alert.show("GPS not supported");
    }
}

private function handleLocationRequest(event:GeolocationEvent):void {
    isGPSOn=1;
    var outSR:SpatialReference = new SpatialReference(4326);
    var tempGeom:Geometry=new MapPoint(event.longitude,event.latitude,outSR);
    outSR= new SpatialReference(3414);
    // Note: GeometryService takes in geometries instead of graphics as input
    geometryService.project([tempGeom], outSR)    
   
   }

hey, thanks for the replies, yes i've written a trace() into the following if statement:

            protected function myMap_loadHandler(event:MapEvent):void
            {
                if (Geolocation.isSupported)
                {trace("geo loop begin");
                    geo = new Geolocation;
                    if (!geo.muted) // check if Geolocation is not disabled on the device
                    {trace("geo on");
                        zoomToCurrentLocationImg.source = m_gpsA;
                        zoomToCurrentLocationImg.visible = true;
                    }
                }
            }

i get the "geo loop begin" trace but not the "geo on", i've checked the device settings and geolocation works fine in all other apps.

any ideas?! do others have this working?

thanks
Ben
0 Kudos
AaronNash
Deactivated User
Here is what I am using, have not tested it on an Iphone yet but works seamlessly. I am also reprojecting the point into a different spatial reference

   private function locate():void
   {
    if (Geolocation.isSupported==true)   
    {
     //Initialize the location sensor.
     geolocation = new Geolocation();
     geolocation.setRequestedUpdateInterval(5000);
     geolocation.addEventListener(GeolocationEvent.UPDATE, onTravel);    
    }
    else
    {
     Alert.show("Geolocation feature not supported");
    }    
   }
   //geolocation event listener  
   private function onTravel(event:GeolocationEvent):void 
   { 
     var long:String = event.longitude.toString();
     var lat:String = event.latitude.toString();
     var longnew:Number = Number(long);
     var latnew:Number = Number(lat);
     var GPSPoint:MapPoint = new MapPoint(longnew, latnew);
     GPSPoint.spatialReference = new SpatialReference(4326); 
     var outSR:SpatialReference = new SpatialReference(2234);    
     geometryService.project([GPSPoint as Geometry], outSR);
   } 
0 Kudos
deleted-user-NnRwwd8ols89
Deactivated User
thanks guys this works now! not sure what it was before, but great to get it working.

has anyone implemented the same location symbol as used by other native iOS apps, the blue dot with the accuracy indicator/circle around it as opposed to the picture marker symbol?!

thanks
Ben
0 Kudos
AaronNash
Deactivated User
Don't think we have the capabilities to do that yet, in the native Android API there I there is something to display the accuracy on the point, HERE is some info on that. I was trying to do something in Flex to accomplish that but have not really gotten anywhere. I was thinking about two symbols to display the GPS location, a center point and then a larger circle underneath, and then having the size of the circle respresent the accuracy of the location. But i did not invest anytime in working through the code, I figured you would need some kind math equation to look at the scale of the map, the accuracy of the GPS, and then draw the circle to accurately represent the accuracy of the GPS signal. Maybe someone else will chime in with a better way, but my math is sub-par and I don't have time to invest in that at the moment
0 Kudos
AaronNash
Deactivated User
I came across a thought on how to create that GPS accuracy polygon. I have not finished the code, haven't had the time. But here is what I started, create a new function like this one
private function bufferGPS():void
   {
    var bufferParameters:BufferParameters = new BufferParameters();
    bufferParameters.geometries = [ map point to buffer ];
    bufferParameters.distances = [this will be where you put the accuracy number];
    // Note: As of version 2.0, the buffer constants have been moved to GeometryService.
    bufferParameters.unit = GeometryService.UNIT_METER;
    bufferParameters.bufferSpatialReference = map.spatialReference;
    bufferParameters.outSpatialReference = map.spatialReference;
    
    geometryService1.addEventListener(GeometryServiceEvent.BUFFER_COMPLETE, bufferCompleteHandler);
    geometryService1.buffer(bufferParameters);
    
    function bufferCompleteHandler(event:GeometryServiceEvent):void
    {
     geometryService1.removeEventListener(GeometryServiceEvent.BUFFER_COMPLETE, bufferCompleteHandler);
     // Note: As of version 2.0, GeometryService returns geometries (instead of graphics)
     for each (var geometry:Polygon in event.result)
     {
      var graphic:Graphic = new Graphic();
      graphic.geometry = geometry;
      graphic.symbol = fillSymbol;
      myGraphicsLayer.add(graphic);
     }
    }


Call the function everytime you update the GPS, the problem I have not had time to resolve is how to get the horizontal accuracy as the bufferParameters.distances. Not sure its the best way to do it, its a call to a geometry service to buffer the map point everytime the GPS updates, but it could work
0 Kudos
TomRauch
Emerging Contributor
Hi, I am trying to execute this script (see below) using Flex 4.5 but I keep getting an error on the line referencing geometryService.project; my Flex compiler says I am accessing an undefined property 'project'.  Any help, much appreciated!  Thank you.

private function onUpdate(event:GeolocationEvent):void
   {
    var long:String = event.longitude.toString();
    var lat:String = event.latitude.toString();
    var longnew:Number = Number(long);
    var latnew:Number = Number(lat);
    var GPSPoint:MapPoint = new MapPoint(longnew, latnew);
    GPSPoint.spatialReference = new SpatialReference(4326);
    var outSR:SpatialReference = new SpatialReference(2234);   
    geometryService.project([GPSPoint as Geometry], outSR);
   
   }
0 Kudos