有没有人对此有所了解?我正在测试AVD.
我做了一个测试,看看我的位置是否已启用,但事实并非如此.我不确定为什么会这样.
这是我的代码:
package com.manita.mapuse;import java.io.inputStream;import org.apache.http.httpentity;import org.apache.http.httpResponse;import org.apache.http.clIEnt.httpClIEnt;import org.apache.http.clIEnt.methods.httpPost;import org.apache.http.impl.clIEnt.DefaulthttpClIEnt;import androID.content.Context;import androID.location.Location;import androID.location.LocationListener;import androID.location.LocationManager;import androID.os.Bundle;import androID.util.Log;import androID.vIEw.KeyEvent;import androID.Widget.Toast;import com.Google.androID.maps.GeoPoint;import com.Google.androID.maps.MapActivity;import com.Google.androID.maps.MapController;import com.Google.androID.maps.MapVIEw;import com.Google.androID.maps.MyLocationOverlay; public class MapuseActivity extends MapActivity implements LocationListener { private MapVIEw mapVIEw = null; private LocationManager lm = null; private double lat = 0; private double lng = 0; private double alt = 0; private MapController mc = null; private MyLocationOverlay myLocation = null; @OverrIDe public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.main); mapVIEw = (MapVIEw) this.findVIEwByID(R.ID.mapVIEw); mapVIEw.setBuiltInZoomControls(true); lm = (LocationManager) this.getSystemService(LOCATION_SERVICE); lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,10000,this); lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,this); mc = mapVIEw.getController(); mc.setZoom(10); myLocation = new MyLocationOverlay(getApplicationContext(),mapVIEw); myLocation.runOnFirstFix(new Runnable() { public voID run() { mc.animateto(myLocation.getMyLocation()); mc.setZoom(10); } }); LocationManager locationManager; String context = Context.LOCATION_SERVICE; locationManager = (LocationManager)getSystemService(context); String provIDer = LocationManager.GPS_PROVIDER; lm.requestLocationUpdates(LocationManager.GPS_PROVIDER,this); Location location = locationManager.getLastKNownLocation(provIDer); locationManager.getProvIDer(provIDer); if(!locationManager.isProvIDerEnabled(provIDer)){ locationManager.setTestProvIDerEnabled(provIDer,true); } boolean enabled = locationManager.isProvIDerEnabled(provIDer); if(enabled){ Toast.makeText(getBaseContext(),"provIDe enabled : Latitude = " + lat + " Longitude = " + lng+" Altitude = " + alt,Toast.LENGTH_SHORT).show(); } else{ Toast.makeText(getBaseContext(),"provIDer Disabled : Latitude = " + lat + " Longitude = " + lng+" Altitude = " + alt,Toast.LENGTH_SHORT).show(); } if(location!=null){ lat = location.getLatitude(); lng = location.getLongitude(); alt = location.getAltitude(); Toast.makeText(getBaseContext(),"provIDerrr enabled : Latitude = " + lat + " Longitude = " + lng+" Altitude = " + alt,Toast.LENGTH_SHORT).show(); } else{ Toast.makeText(getBaseContext(),"location not found : Latitude = " + lat + " Longitude = " + lng+" Altitude = " + alt,Toast.LENGTH_SHORT).show(); } mapVIEw.getoverlays().add(myLocation); if (myLocation.isMyLocationEnabled()!=false) { GeoPoint p =myLocation.getMyLocation(); lat= p.getLatitudeE6(); lng= p.getLongitudeE6(); alt = location.getAltitude(); Toast.makeText(getBaseContext(),"geolocalisation activé lat: "+lat+ " long: " +lng +" Altitude = " + alt,Toast.LENGTH_SHORT).show(); } else { Toast.makeText(getBaseContext(),"geolocalisation desactivée",Toast.LENGTH_SHORT).show(); } // appel de la fonction insert values insertvalues(lat,lng); } @OverrIDe protected voID onResume() { super.onResume(); myLocation.enableMyLocation(); myLocation.enableCompass(); } @OverrIDe protected boolean isRoutedisplayed() { return false; } @OverrIDe public boolean onKeyDown(int keyCode,KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_S) { mapVIEw.setSatellite(!mapVIEw.isSatellite()); return true; } if (keyCode == KeyEvent.KEYCODE_T) { mapVIEw.setSatellite(!mapVIEw.isTraffic()); return true; } return super.onKeyDown(keyCode,event); } @OverrIDe public voID onLocationChanged(Location location) { lat = location.getLatitude(); lng = location.getLongitude(); Toast.makeText( getBaseContext(),"Location change to : Latitude = " + lat + " Longitude = " + lng,Toast.LENGTH_SHORT).show(); GeoPoint p = new GeoPoint((int) (lat * 1E6),(int) (lng * 1E6)); mc.animateto(p); mc.setCenter(p); } @OverrIDe public voID onProvIDerDisabled(String provIDer) { } @OverrIDe public voID onProvIDerEnabled(String provIDer) { } @OverrIDe public voID onStatusChanged(String provIDer,int status,Bundle extras) { } ///// insert valeurs .... public voID insertvalues(double lat,double lng){ //http post c à d envoi des données try{ httpClIEnt httpclIEnt = new DefaulthttpClIEnt(); httpPost httppost = new httpPost("http://www.pizza-paris.com/clic/marwa/test/form.PHP?latitude="+lat+"&longitude="+lng); httpResponse response = httpclIEnt.execute(httppost); httpentity entity = response.getEntity(); inputStream is = entity.getContent(); Log.i("postData",response.getStatusline().toString()); } catch(Exception e) { Log.e("log_tag","Error in http connection "+e.toString()); } } }
谢谢!
解决方法 除非您的PC / Mac具有GPS,否则AVD无法检测您的位置.使用真实设备或手动输入值来测试程序. 总结以上是内存溢出为你收集整理的android gps当前位置全部内容,希望文章能够帮你解决android gps当前位置所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)