2012-09-05 69 views

回答

0

我得到最近的地方當你說「sql lite數據庫」時不知道你的意思,因爲當前位置不應該存儲在手機的任何數據庫中,除非你明確地將它存儲在不同的應用程序中。

這應該是您的主要活動:

LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
LocationListener locationlistener = new mylocationlistener(); 
locationmanager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationlistener); 

...

private class mylocationlistener implements LocationListener{ 
    @Override 
    public void onLocationChanged(Location location) { 
     if (location != null) { 
      Log.d("latitude", location.getLatitude()); 
      Log.d("longitude", location.getLongitude());     
     }    
    } 
} 
2

我不知道爲什麼你正在使用的電話數據庫來存儲所有地點。它更安全的使用服務器端。 假設您已將經緯度保存在數據庫表中,則僅在查詢中需要進行修改。以下是解決我的問題的SQL查詢:

"SELECT * FROM places WHERE (acos(sin(places.lat * 0.0175) * sin($userLat * 0.0175) + cos(places.lat * 0.0175) * cos($userLat * 0.0175) * cos(($userLon * 0.0175) - (places.lon * 0.0175))) * 3959 <= $locateRadius)" 
//userLat and userLon refer to your current location 
相關問題