i am just trying to get practiced with phone gap for android devices. I found an map based app here
Following is the javascript i tried to run
<html>
<head>
<meta name="viewport" content="width=device-width; height=device-height; user-scalable=no" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Beer Me</title>
<link rel="stylesheet" href="/master.css" type="text/css" media="screen" />
<script type="text/javascript" src="scripts/phonegap.js"></script>
<script type="text/javascript">
function loader()
{
var state = document.readyState;
if (state == 'loaded' || state == 'complete')
{
run();
}
else
{
if (navigator.userAgent.indexOf('Browzr') > -1)
{
setTimeout(run, 250);
}
else
{
document.addEventListener('deviceready',run,false);
}
}
}
function run()
{
var win = function(position) { // Grab coordinates object from the Position object passed into success callback.
var coords = position.coords;
var url = "http://maps.google.com/maps/api/staticmap?center=" + coords.latitude + "," + coords.longitude + "&zoom=13&size=320x480&maptype=roadmap&key=xxxxxxxxxxxxxxxxxxx&sensor=true";
document.getElementById('map').setAttribute('src',url);
};
var fail = function(e)
{
alert('Can\'t retrieve position.\nError: ' + e);
};
navigator.geolocation.getCurrentPosition(win, fail);
}
</script>
</head>
<body onload="loader();">
<img id="map" />
</body>
</html>
when i run in the android device it shows an alert box that Can\'t retrieve position.
The function for Position is not been called. How to get the position of a place in phone gap javascript, please help me….
Well, if you are talking about that exact code, it looks like it wants a key for google maps. That tutorial is a year old which is ancient in google map time.
If you are willing to move to Google Maps JavaScript v3 (non-static – no key, much more powerful and interesting to use than static maps), here’s a gettting-started google map route finder tutorial. It’s also from the phonegap wiki pages, see android tutorials, scroll down to the one titled jQuery Google Maps Plugin for Google Maps v3: Route Finder App.