Java 从android传递到web的位置始终为999.9999
我可以使用php和android java成功地将我的位置传递到我的web服务。但问题是我的经度和纬度都是999.99999和-999.99999。你能指出我犯了什么错误吗 这是我的密码: **Java 从android传递到web的位置始终为999.9999,java,android,database,location,Java,Android,Database,Location,我可以使用php和android java成功地将我的位置传递到我的web服务。但问题是我的经度和纬度都是999.99999和-999.99999。你能指出我犯了什么错误吗 这是我的密码: ** 公共类LocationGetter扩展MapActivity实现LocationListener{// 私有静态最终字符串TAG=“LocationActivity”; LocationManager LocationManager;// 地理编码器地理编码器;// 文本视图位置文本; 地图视图; Ma
公共类LocationGetter扩展MapActivity实现LocationListener{//
私有静态最终字符串TAG=“LocationActivity”;
LocationManager LocationManager;//
地理编码器地理编码器;//
文本视图位置文本;
地图视图;
MapController MapController;//
//**此声明用于向web服务传递数据
//进度对话框
私人对话;
//JSONParser对象创建
JSONParser JSONParser=新的JSONParser();
//将位置传递到web的url
//私有静态字符串url\u创建\u产品=
// "http://student-thesis.netii.net/location_adding.php";
私有静态字符串url\u创建\u产品=”http://10.0.2.2/TheCalling/location_adding.php";
//JSON节点名称
私有静态最终字符串标记_SUCCESS=“SUCCESS”;
//经纬度
私有静态字符串Ilatude;
私有静态字符串i长度;
//**结束
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.maps);
locationText=(TextView)this.findViewById(R.id.lblLocationInfo);
map=(MapView)this.findViewById(R.id.MapView);
map.setBuiltInZoomControls(真);
mapController=map.getController();//
mapController.setZoom(19);
locationManager=(locationManager)此
.getSystemService(位置服务);//
地理编码器=新地理编码器(此);//
位置=位置管理器
.getLastKnownLocation(LocationManager.GPS_提供程序);//
如果(位置!=null){
Log.d(标记,location.toString());
此.onLocationChanged(位置);//
}
}
@凌驾
受保护的void onResume(){
super.onResume();
locationManager.RequestLocationUpdate(locationManager.GPS\U提供程序,
60000,5,这个);//
}
@凌驾
受保护的void onPause(){
super.onPause();
locationManager.RemoveUpdate(此);//
}
@凌驾
public void onLocationChanged(位置位置){//
Log.d(标记“onLocationChanged with location”+location.toString());
String text=String.format(
“Lat:\t%f\n长:\t%f\n长:\t%f\n长:\t%f\n长:\t%f\n”,
location.getLatitude(),location.getLatitude(),
location.getAltitude(),location.getBearing());
this.locationText.setText(text);
试一试{
列表地址=geocoder.getFromLocation(
location.getLatitude(),location.getLatitude(),10);//
收件人(地址:地址){
this.locationText.append(“+address.getAddressLine(0));
}
int纬度=(int)(location.getLatitude()*1000000);
int longitude=(int)(location.getLongitude()*1000000);
地质点=新的地质点(纬度、经度);
mapController.animateTo(点);//
List mapOverlays=map.getOverlays();
Drawable Drawable=this.getResources().getDrawable(
R.可拉深的红点);
AddItemizedOverlay itemizedOverlay=新的AddItemizedOverlay(
可拉拔的,这个);
OverlayItem OverlayItem=新的OverlayItem(点“Hello”,
“样本覆盖项目”);
itemizedOverlay.addOverlay(overlayitem);
添加(itemizedOverlay);
ILatitude=整数.toString(纬度);
ILongitude=整数.toString(经度);
新建phpconnect().execute();
}捕获(IOE异常){
Log.e(“LocateMe”,“无法获取地理编码器数据”,e);
}
}
@凌驾
公共无效onProviderDisabled(字符串提供程序){
//TODO自动生成的方法存根
}
@凌驾
公共无效onProviderEnabled(字符串提供程序){
//TODO自动生成的方法存根
}
@凌驾
public void onStatusChanged(字符串提供程序、int状态、Bundle extra){
//TODO自动生成的方法存根
}
@凌驾
受保护的布尔值isRouteDisplayed(){
//TODO自动生成的方法存根
返回false;
}
类phpconnect扩展了异步任务{
@凌驾
受保护的字符串doInBackground(字符串…args){
字符串strLatitude=ILatitude;
字符串长度=i长度;
//建筑参数
List params1=new ArrayList();
参数1.添加(新的BasicNameValuePair(“纬度”,标准纬度));
参数1.添加(新的BasicNameValuePair(“经度”,标准长度));
//获取JSON对象
//请注意,创建产品url接受POST方法
JSONObject json=jsonParser.makeHttpRequest(url\u create\u product,
“职位”,参数1);
//检查cat fro响应日志
d(“创建响应”,json.toString());
试一试{
int success=json.getInt(TAG_success);
如果(成功==1){
//成功更新
}否则{
//未能创建产品
}
}捕获(JSONException e){
e、 printStackTrace();
}
返回null;
}
}
}
**
提前谢谢各位
嗯,我想我不需要在这里发布我的php代码,但如果您想查看,请通知我。:) 我猜您的数字超出了int的界限。请尝试使用biginger或long prim
public class LocationGetter extends MapActivity implements LocationListener { // <1>
private static final String TAG = "LocationActivity";
LocationManager locationManager; // <2>
Geocoder geocoder; // <3>
TextView locationText;
MapView map;
MapController mapController; // <4>
// ** This declarations was for passing of data to web service
// Progress Dialog
private ProgressDialog pDialog;
// JSONParser Object creation
JSONParser jsonParser = new JSONParser();
// url to pass location to web
// private static String url_create_product =
// "http://student-thesis.netii.net/location_adding.php";
private static String url_create_product = "http://10.0.2.2/TheCalling/location_adding.php";
// JSON Node names
private static final String TAG_SUCCESS = "success";
//Latitude and Longitude
private static String ILatitude;
private static String ILongitude;
// ** End
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.maps);
locationText = (TextView) this.findViewById(R.id.lblLocationInfo);
map = (MapView) this.findViewById(R.id.mapview);
map.setBuiltInZoomControls(true);
mapController = map.getController(); // <4>
mapController.setZoom(19);
locationManager = (LocationManager) this
.getSystemService(LOCATION_SERVICE); // <2>
geocoder = new Geocoder(this); // <3>
Location location = locationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER); // <5>
if (location != null) {
Log.d(TAG, location.toString());
this.onLocationChanged(location); // <6>
}
}
@Override
protected void onResume() {
super.onResume();
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
60000, 5, this); // <7>
}
@Override
protected void onPause() {
super.onPause();
locationManager.removeUpdates(this); // <8>
}
@Override
public void onLocationChanged(Location location) { // <9>
Log.d(TAG, "onLocationChanged with location " + location.toString());
String text = String.format(
"Lat:\t %f\nLong:\t %f\nAlt:\t %f\nBearing:\t %f \n",
location.getLatitude(), location.getLongitude(),
location.getAltitude(), location.getBearing());
this.locationText.setText(text);
try {
List<Address> addresses = geocoder.getFromLocation(
location.getLatitude(), location.getLongitude(), 10); // <10>
for (Address address : addresses) {
this.locationText.append(" " + address.getAddressLine(0));
}
int latitude = (int) (location.getLatitude() * 1000000);
int longitude = (int) (location.getLongitude() * 1000000);
GeoPoint point = new GeoPoint(latitude, longitude);
mapController.animateTo(point); // <11>
List<Overlay> mapOverlays = map.getOverlays();
Drawable drawable = this.getResources().getDrawable(
R.drawable.reddot);
AddItemizedOverlay itemizedOverlay = new AddItemizedOverlay(
drawable, this);
OverlayItem overlayitem = new OverlayItem(point, "Hello",
"Sample Overlay item");
itemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemizedOverlay);
ILatitude = Integer.toString(latitude);
ILongitude = Integer.toString(longitude);
new phpconnect().execute();
} catch (IOException e) {
Log.e("LocateMe", "Could not get Geocoder data", e);
}
}
@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
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
class phpconnect extends AsyncTask<String, String, String> {
@Override
protected String doInBackground(String... args) {
String strLatitude = ILatitude;
String strLongitude = ILongitude;
// Building parameters
List<NameValuePair> params1 = new ArrayList<NameValuePair>();
params1.add(new BasicNameValuePair("latitude", strLatitude));
params1.add(new BasicNameValuePair("longitude", strLongitude));
// getting JSON Object
// Note that create product url accepts POST method
JSONObject json = jsonParser.makeHttpRequest(url_create_product,
"POST", params1);
// check log cat fro response
Log.d("Create Response", json.toString());
try {
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// successfully updated
} else {
// failed to create product
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
}
}