为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

android 地图开发

2011-10-05 4页 doc 27KB 64阅读

用户头像

is_919220

暂无简介

举报
android 地图开发package com.GPSMAP; package com.GPSMAP; 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 android.content.Context; import android.content....
android  地图开发
package com.GPSMAP; package com.GPSMAP; 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 android.content.Context; import android.content.Intent; import android.location.Criteria; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.provider.Settings; import android.util.Log; import android.widget.TextView; import android.widget.Toast; public class GPSMAP extends MapActivity { TextView text1; int IntentGPS = 0x0000100; private MapController mapController; private GeoPoint getPoint; private MapView mapView ; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); text1 = (TextView) findViewById(R.id.text1); if (openGPSSettions()) getLoaction(); mapView = (MapView)findViewById(R.id.mapview1); mapController=mapView.getController(); Log.d("gPsMAP", "1"); mapView.setEnabled(true); mapView.setClickable(true); mapView.setBuiltInZoomControls(true); Log.d("gPsMAP", "3"); mapController.setZoom(8); } @Override protected boolean isRouteDisplayed() { // TODO Auto-generated method stub return false; } private void getLoaction() { LocationManager locationManager = null; String serviceName = Context.LOCATION_SERVICE; // 服务名称 locationManager = (LocationManager) this.getSystemService(serviceName); // 获取位置信息 Criteria criteria = new Criteria(); // 声明一个标准 criteria.setAccuracy(Criteria.ACCURACY_COARSE);// 精度 criteria.setAltitudeRequired(false); // 海拔 criteria.setPowerRequirement(Criteria.POWER_LOW); // 低功率 String provider = locationManager.getBestProvider(criteria, true); // 获取GPS信息 Location location = locationManager.getLastKnownLocation(provider); // 获取GPS最后一个知道的信息 getNewPosition(location); locationManager.requestLocationUpdates(provider, 10 * 1000, 50, locationlistener); // 添加移动或者是时间变化监听 } private final LocationListener locationlistener = new LocationListener() { public void onStatusChanged(String provider, int status, Bundle extras) { // TODO Auto-generated method stub } public void onProviderEnabled(String provider) { // TODO Auto-generated method stub } public void onProviderDisabled(String provider) { // TODO Auto-generated method stub } public void onLocationChanged(Location location) { // TODO Auto-generated method stub getNewPosition(location); showMap(location); } }; private void getNewPosition(Location location) { if (location != null) { double lat = location.getLatitude(); // 纬度 double lng = location.getLongitude(); // 经度 text1.setText("维度:" + lat + "\n经度" + lng); } else { text1.setText("无法获取地理信息"); } } private boolean openGPSSettions() { LocationManager locationManager = (LocationManager) this .getSystemService(Context.LOCATION_SERVICE); if (locationManager .isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) { Toast.makeText(this, "GPS模块正常", Toast.LENGTH_SHORT).show(); return true; } Toast.makeText(this, "请开启GPS模块", Toast.LENGTH_SHORT).show(); Intent intent = new Intent(Settings.ACTION_SECURITY_SETTINGS); startActivityForResult(intent, IntentGPS); // 此为设置完成后返回到获取界面 return false; } private void showMap(Location location) { getPoint = new GeoPoint((int)location.getLatitude()*1000000,(int)location.getLongitude()*1000000); mapController.animateTo(getPoint); Toast.makeText(this,"纬度:"+location.getLatitude()+" 经度:"+location.getLongitude(), Toast.LENGTH_SHORT).show(); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { // TODO Auto-generated method stub if (requestCode == IntentGPS && resultCode == RESULT_OK) { getLoaction(); } super.onActivityResult(requestCode, resultCode, data); } } Main 的布局 -
/
本文档为【android 地图开发】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索