mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-19 07:02:51 +08:00
half GPS problems fixed..Device.Location.init works nd can get first GPS read
This commit is contained in:
parent
fe74ca3ec7
commit
6e59af7e0c
@ -158,7 +158,7 @@ var Device = {
|
|||||||
|
|
||||||
Device.uuid = window.IPodGap.getUuid();
|
Device.uuid = window.IPodGap.getUuid();
|
||||||
|
|
||||||
Device.gapVersion = window.IPoddGap.getVersion();
|
Device.gapVersion = window.IPodGap.getVersion();
|
||||||
|
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
@ -178,28 +178,34 @@ var Device = {
|
|||||||
exec: function(command) {
|
exec: function(command) {
|
||||||
// Different platforms have different ways the js browser bridge is called
|
// Different platforms have different ways the js browser bridge is called
|
||||||
// to get a native object so we handle each difference
|
// to get a native object so we handle each difference
|
||||||
|
//
|
||||||
|
|
||||||
|
|
||||||
if (Device.available || Device.whatPlatform == "IPhone") {
|
|
||||||
|
if ( Device.whatPlatform == "IPhone") {
|
||||||
|
try {
|
||||||
|
|
||||||
|
document.location = "gap:" + command;
|
||||||
|
} catch(e) {
|
||||||
|
console.log("Command '" + command + "' has not been executed, because of exception: " + e);
|
||||||
|
alert("Error executing command '" + command + "'.")
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
if ( Device.whatPlatform == "IPod") {
|
||||||
try {
|
try {
|
||||||
document.location = "gap:" + command;
|
document.location = "gap:" + command;
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.log("Command '" + command + "' has not been executed, because of exception: " + e);
|
console.log("Command '" + command + "' has not been executed, because of exception: " + e);
|
||||||
alert("Error executing command '" + command + "'.")
|
alert("Error executing command '" + command + "'.")
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
if (Device.available || Device.whatPlatform == "IPod") {
|
if (Device.whatPlatform == "Android" || command == "getloc") {
|
||||||
try {
|
try {
|
||||||
document.location = "gap:" + command;
|
alert('start here');
|
||||||
} catch(e) {
|
|
||||||
console.log("Command '" + command + "' has not been executed, because of exception: " + e);
|
document.location="javascript:window.DroidGap.getLocation()";
|
||||||
alert("Error executing command '" + command + "'.")
|
|
||||||
}
|
alert('window.DroidGap.getLocation()=' + window.DroidGap.getLocation());
|
||||||
}
|
|
||||||
if (Device.available || Device.whatPlatform == "Android" || command == "getloc") {
|
|
||||||
try {
|
|
||||||
document.location = "javascript:" + "window.DroidGap.getLocation()";
|
|
||||||
alert('document.location=' + document.location);
|
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
console.log("Command '" + command + "' has not been executed, because of exception: " + e);
|
console.log("Command '" + command + "' has not been executed, because of exception: " + e);
|
||||||
alert("Error executing command '" + command + "'.")
|
alert("Error executing command '" + command + "'.")
|
||||||
@ -217,7 +223,8 @@ var Device = {
|
|||||||
|
|
||||||
init: function() {
|
init: function() {
|
||||||
Device.exec("getloc");
|
Device.exec("getloc");
|
||||||
alert('initialized Location function and getloc was called');
|
alert(' getloc was called');
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
set: function(lat, lon) {
|
set: function(lat, lon) {
|
||||||
@ -275,6 +282,7 @@ var Device = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function gotLocation(lat, lon) {
|
function gotLocation(lat, lon) {
|
||||||
|
alert('gotLocation lat=' + lat + " gotLocation lon=" + lon);
|
||||||
return Device.Location.set(lat, lon)
|
return Device.Location.set(lat, lon)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,18 +9,17 @@
|
|||||||
<style type="text/css" media="screen">@import "file:///android_asset/iui.css";</style>
|
<style type="text/css" media="screen">@import "file:///android_asset/iui.css";</style>
|
||||||
<script type="application/x-javascript" src="file:///android_asset/iui.js"></script>
|
<script type="application/x-javascript" src="file:///android_asset/iui.js"></script>
|
||||||
<script type="application/x-javascript" src="file:///android_asset/gap.js"></script>
|
<script type="application/x-javascript" src="file:///android_asset/gap.js"></script>
|
||||||
<!-- iBug from JoeHewitt.com requires a certain iBug.js script located in
|
|
||||||
the directory you launched the mini python server component of iBug
|
|
||||||
in the format of src=http://hostname:port/iBug.js
|
|
||||||
if you are not using to debug comment out
|
|
||||||
-->
|
|
||||||
<!-- <script type="application/x-javascript" src="http://192.168.1.20:1840/ibug.js"></script> -->
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
initGap = function() {
|
initGap = function() {
|
||||||
|
// Device.init() initializes OS-Device values
|
||||||
Device.init();
|
Device.init();
|
||||||
|
// Device.Location.callback = updateLocation sets to funciotn updateLocation so that lat and lon can be passed
|
||||||
Device.Location.callback = updateLocation;
|
Device.Location.callback = updateLocation;
|
||||||
|
// Device.Location.init() to initalize location
|
||||||
|
|
||||||
//Device.Acceleration.callback = updateAccel;
|
//Device.Acceleration.callback = updateAccel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,6 +45,7 @@ updateSettings = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateLocation = function(lat,lon) {
|
updateLocation = function(lat,lon) {
|
||||||
|
alert('lat=' + lat + ' lon=' + lon);
|
||||||
$('lat').value = lat;
|
$('lat').value = lat;
|
||||||
$('lon').value = lon;
|
$('lon').value = lon;
|
||||||
}
|
}
|
||||||
@ -115,7 +115,7 @@ addLoadEvent(initGap);
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="geo" title="Geo Location" class="panel">
|
<div id="geo" title="Geo Location" class="panel">
|
||||||
|
<form id="searchForm" action="POST">
|
||||||
<h2>Location</h2>
|
<h2>Location</h2>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
@ -127,10 +127,10 @@ addLoadEvent(initGap);
|
|||||||
<input disabled="enabled" name="lon" id="lon" value="" type="text"></input>
|
<input disabled="enabled" name="lon" id="lon" value="" type="text"></input>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<a class="button blueButton" type="submit" onclick="Device.Location.init();">Update Location</a>
|
<a class="button blueButton" type="submit" onclick="updateLocation();">Update Location</a>
|
||||||
</div>
|
</div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="accel" title="Accelerometer" class="panel">
|
<div id="accel" title="Accelerometer" class="panel">
|
||||||
|
@ -28,6 +28,7 @@ import android.hardware.SensorManager;
|
|||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.location.LocationManager;
|
import android.location.LocationManager;
|
||||||
import android.location.LocationListener;
|
import android.location.LocationListener;
|
||||||
|
import android.location.LocationProvider;
|
||||||
import android.media.MediaPlayer;
|
import android.media.MediaPlayer;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@ -49,6 +50,7 @@ public class PhoneGap{
|
|||||||
private WebView mAppView;
|
private WebView mAppView;
|
||||||
private GpsListener mGps;
|
private GpsListener mGps;
|
||||||
private NetworkListener mNetwork;
|
private NetworkListener mNetwork;
|
||||||
|
protected LocationProvider provider;
|
||||||
|
|
||||||
public PhoneGap(Context ctx, Handler handler, WebView appView) {
|
public PhoneGap(Context ctx, Handler handler, WebView appView) {
|
||||||
this.mCtx = ctx;
|
this.mCtx = ctx;
|
||||||
@ -84,11 +86,9 @@ public class PhoneGap{
|
|||||||
vibrator.vibrate(pattern);
|
vibrator.vibrate(pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Android requires a provider, since it can fall back on triangulation and other means as well as GPS
|
|
||||||
*/
|
|
||||||
|
|
||||||
public void getLocation(final String provider){
|
|
||||||
|
public void getLocation( ){
|
||||||
mHandler.post(new Runnable() {
|
mHandler.post(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
GeoTuple geoloc = new GeoTuple();
|
GeoTuple geoloc = new GeoTuple();
|
||||||
|
Loading…
Reference in New Issue
Block a user