LocateButton on locate event

741
3
01-23-2014 02:28 PM
TomSellsted
MVP Regular Contributor
Greetings!

I am working with the LocateButton and trying to get some information about the point when the on 'locate' event fires.  It looks like it is supposed provide graphic, position and scale information, but I guess I am not sure what the proper syntax is to return this information.  This is my code:

var geoLocate = new LocateButton({
   map: map,
   setScale: false,
   centerAt: false
}, "LocateButton");
geoLocate.startup();
geoLocate.on('locate',gpsUpdate);
  
function gpsUpdate(gps) {
   // do fun things with GPS info
}


Thanks for any help!
0 Kudos
3 Replies
RobertoPepato
Occasional Contributor II
Greetings!

I am working with the LocateButton and trying to get some information about the point when the on 'locate' event fires.  It looks like it is supposed provide graphic, position and scale information, but I guess I am not sure what the proper syntax is to return this information.  This is my code:

var geoLocate = new LocateButton({
   map: map,
   setScale: false,
   centerAt: false
}, "LocateButton");
geoLocate.startup();
geoLocate.on('locate',gpsUpdate);
  
function gpsUpdate(gps) {
   // do fun things with GPS info
}


Thanks for any help!


The information you are looking for is provided through the function parameter. As you are naming the parameter 'gps' you can access the info this way:

gps.graphic
gps.position
gps.scale
0 Kudos
TomSellsted
MVP Regular Contributor
My apologies Roberto, I should have been more clear with my request.  Those are exactly the objects I am expecting to be returned when the locate event is fired.  I am not receiving that object.  The event appears to be fired when the request is made, not when the position is returned.  How do I get the result of the position being found?

Thanks very much!
0 Kudos
RobertoPepato
Occasional Contributor II
Sorry Tom, I think that I got it now.

Take a look at this fiddle with the implementation that I think you're looking for.

See some prints of this in action below:

[ATTACH=CONFIG]30855[/ATTACH]

[ATTACH=CONFIG]30856[/ATTACH]

The second screenshot will be displayed when you click on a point that could not be reverse-geocoded, like for example, a click on the ocean or between streets outside of the range you specified.

Let me know if it helps.

Regards,

Roberto Pepato.
0 Kudos