On Nov 14, 8:10 pm, Tue Nguyen <[email protected]> wrote: > I got some problems > > I wanna get my current position and do somthing with it. I use > navigator.geolocation.getCurrentPosition function like this: > > $(document).ready(function(){ > var current_location; > navigator.geolocation.getCurrentPosition(function(position) { > current_location = position; > }); > > // do something with current_location}); > > But I cant assign possition to current_location.
You are assigning a position to current_location, however, current_position is local to the callback routine. > What' wrong? current_position is local to the callback routine, it goes out of scope when the callback routine ends. Best practice is to use the position data in the callback routine when it is available. You can save it in a _global_ variable to use later, but beware, later is later in time not further down in your code. -- Larry > and can > u show me how to assign the position value to an variable in order to > use it out of navigator.geolocation.getCurrentPosition scope? > > Thanks for ur help > > p/s: my English is not very good :) -- You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.
