android gps位置日志,android gps当前位置

我想显示我当前的位置,但它显示了我在命令行上设置的纬度和经度!如果我没有在命令行上设置参数,它会显示

Eclipse中包含的纬度和经度!

有没有人对此有所了解?我正在测试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());

}

}

}

谢谢!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值