Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

google gears geolocation getCurrentPosition()

android innerHTML

  • Please log in to reply
4 replies to this topic

#1 jerrywickey

jerrywickey

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 51 posts

Posted 22 February 2012 - 09:03 PM

Using geoposition and can't get accuracy any better than 1700 meters.

I am testing on an android tablet and see the gps status indicator indicate activity each time my javascript calls for a current position, but never get a position accuracy better than 1700 meters. I checked the returned lat and lon against a dedicated gps receiver and sure enough it is 1000 to 2000 meter from the tablets actual location.

I am using a third party cabs/geo.js and I suspect that may be the issue, but I cant find any short cuts to google gears geolocation. And I am getting lat and lon as well as gps activity indicators.

Anyone know something about this? I am reading google stuff while waiting on someone's response.

Yeah I am aware the timeout could exceed the interval, which could result in an older coordinate replacing a newer, but that isn't the problem.

What stupid mistake am I making?

<script src="http://code.google.com/apis/gears/gears_init.js" type="text/javascript"></script>
<script src="cabs/geo.js" type="text/javascript" ></script>

geo_position_js.init(){}
setInterval("clock()", 2000);

function clock(){
  geo_position_js.getCurrentPosition(callbackgood, callbackbad,{enableHighAccuracy:true , timeout: 10000});
  // other clock stuff
}

function callbackgood(p){
  geolat= p.coords.latitude.toFixed(3);
  geolon= p.coords.longitude.toFixed(3);
  geoacc= p.coords.accuracy;
  // use these globally elsewhere
  document.getElementById('location').innerHTML= geolat+'/'+geolon+' ('+geoacc+')';
}


---------- Post added 02-23-2012 at 12:03 AM ---------- Previous post was 02-22-2012 at 11:40 PM ----------

Either google docs aren't very helpful or I am missing something stupid. Which isn't all that unusual for me.

Google gives the following example

<script src="http://code.google.com/apis/gears/gears_init.js" type="text/javascript"></script>

<script type="text/javascript">
var geo = google.gears.factory.create('beta.geolocation');

function updatePosition(position) {
  alert('Current lat/lon is: ' + position.latitude + ',' + position.longitude +' '+position.accuracy);
}

function handleError(positionError) {
  alert('Attempt to get location failed: ' + positionError.message);
}

geo.getCurrentPosition(updatePosition, handleError);

Ok. So where is google defined?

Sure enough the code throws an error right there.

Did I miss something simple?
  • 0

#2 lethalwire

lethalwire

    while(false){ ... }

  • Senior Member
  • PipPipPipPipPipPip
  • 766 posts
  • Programming Language:C, Java, PHP, JavaScript
  • Learning:PHP

Posted 23 February 2012 - 03:21 PM

You might try posting this in the javascript JavaScript and CSS section. :)
  • 0

#3 jerrywickey

jerrywickey

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 51 posts

Posted 25 February 2012 - 06:19 AM

Sure.

Sorry.

So copy and paste, or is there a way to move it?

Jerry
  • 0

#4 lethalwire

lethalwire

    while(false){ ... }

  • Senior Member
  • PipPipPipPipPipPip
  • 766 posts
  • Programming Language:C, Java, PHP, JavaScript
  • Learning:PHP

Posted 25 February 2012 - 09:23 AM

I'll see if I can get a mod to move it.
  • 0

#5 jerrywickey

jerrywickey

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 51 posts

Posted 25 February 2012 - 04:42 PM

In the mean time I found that google gears is old new.

I am now looking at navigator.geolocation.getCurrentPosition(

But have not yet gotten a working sample

Any help would be great.

Jerry

---------- Post added at 07:42 PM ---------- Previous post was at 06:46 PM ----------

Got it!

It was super simple.

This'll do it.

function foundloaction(p){
  alert('Your current Latitude: '+p.coords.latitude+' / Longitude: '+p.coords.longitude);
}

function errorm(e){
  alert(e.message);
}

if (navigator.geolocation){  
  navigator.geolocation.watchPosition(foundloaction, errorm, {enableHighAccuracy: true});
}else{  
  alert("geolocation is not available");  
}  


  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download