2013-01-07 63 views
0

我有一個應用程序寫在HTML5和包裝在PhoneGaponlocationchanged函數從來沒有叫 - > PhoneGap

我有一個應用程序的地圖,我想通過GPS找到用戶的位置。

我嘗試了以下方式:

在JS我有改變標記的位置的功能:

function GPS(lat, lon) { 
    alert('Now U move'); 
    var CurrentPosition = new google.maps.LatLng(lat, lon); 
    markerMyLoc.setPosition(CurrentPosition); 
} 

在Java中,我有上位置保健功能和發送的JS功能:

public class MainActivity extends DroidGap { 

private LocationManager locationManager; 
private LocationListener locationListener; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    super.setIntegerProperty("splashscreen", R.drawable.splash); 
    super.loadUrl("file:///android_asset/www/XXX.html", 10000); 

    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 

    locationListener = new GPSLocationListener(); 

     locationManager.requestLocationUpdates(
     LocationManager.GPS_PROVIDER, 
     0, 
     0, 
     locationListener); 

    } 
} 

GPSLocationListener類:

public class GPSLocationListener implements LocationListener 
{ 
    @Override 
    public void onLocationChanged(Location location) { 
    if (location != null) { 
     GPScls MyGPS= new GPScls(); 
     MyGPS.GPS(location.getLatitude(),location.getLongitude()); 
    } 
    } 

@Override 
public void onProviderDisabled(String provider) { 
    // TODO Auto-generated method stub 

} 

@Override 
public void onProviderEnabled(String provider) { 
    // TODO Auto-generated method stub 

} 

@Override 
public void onStatusChanged(String provider, int status, Bundle extras) { 
    // TODO Auto-generated method stub 

} 
} 

GPScls類:

public class GPScls extends DroidGap { 
    public void GPS(double latitude,double longitude) { 
     super.loadUrl("javascript:GPS("+latitude+","+longitude+")"); 
    } 
} 

警報:alert('Now U move');沒有顯示出來,任何人都可以幫我解決這個問題?

+0

我希望設備的每一個動作,會出現消息(即運行功能),如果您還可以告訴我如何映射以便在設備移動的方向上移動? –

回答