package org.crazyit.map;
import java.util.List;
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.Overlay;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
// 必须继承MapActivity
public class LocationMap extends MapActivity
{
// 定义界面上的的可视化控件
RadioGroup mapType;
MapView mv;
// 定义MapController对象
MapController controller;
Bitmap posBitmap;
// 定义LocationManager对象
private LocationManager locManager;
//Location 对象
private Location location;
private double dLong=12;
private double dLat=12;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
posBitmap = BitmapFactory.decodeResource(getResources(),R.drawable.pos);
// 获得界面上MapView对象
mv = (MapView) findViewById(R.id.mv);
// 创建LocationManager对象
locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
// 从GPS获取最近的最近的定位信息
location= locManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
// 设置显示放大、缩小的控制按钮
mv.setBuiltInZoomControls(true);
// 创建MapController对象
controller = mv.getController();
//--------------
updateView(location);
// 设置每1秒获取一次GPS的定位信息
locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER
, 1000, 8, new LocationListener()
{
@Override
public void onLocationChanged(Location location)
{
// 当GPS定位信息发生改变时,更新位置
updateView(location);
dLong = location.getLatitude();
dLat = location.getLongitude();
// 调用方法更新MapView
updateMapView(dLong , dLat);
}
@Override
public void onProviderDisabled(String provider)
{
updateView(null);
}
@Override
public void onProviderEnabled(String provider)
{
// 当GPS LocationProvider可用时,更新位置
updateView(locManager
.getLastKnownLocation(provider));
}
@Override
public void onStatusChanged(String provider, int status,
Bundle extras)
{
}
});
// 获得RadioGroup对象
mapType = (RadioGroup) findViewById(R.id.rg);
// 为RadioGroup的选中状态改变添加监听器
mapType.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(RadioGroup group, int checkedId)
{
switch(checkedId)
{
// 如果勾选的是"正常视图"的单选框
case R.id.normal:
mv.setSatellite(false);
break;
// 如果勾选的是"卫星视图"的单选框
case R.id.satellite:
mv.setSatellite(true);
break;
}
}
});
}
@Override
protected boolean isRouteDisplayed()
{
return true;
}
// 根据经度、纬度将MapView定位到指定地点的方法
private void updateMapView(double lng, double lat)
{
// 将经纬度信息包装成GeoPoint对象
GeoPoint gp = new GeoPoint((int) (lat * 1E6)
, (int) (lng * 1E6));
// 设置显示放大缩小按钮
mv.displayZoomControls(true);
// 将地图移动到指定的地理位置
controller.animateTo(gp);
// 获得MapView上原有的Overlay对象
List<Overlay> ol = mv.getOverlays();
// 清除原有的Overlay对象
ol.clear();
// 添加一个新的OverLay对象
ol.add(new PosOverLay(gp, posBitmap));
}
// 更新EditText中显示的内容
public void updateView(Location newLocation)
{
dLong = location.getLatitude();
dLat = location.getLongitude();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
LocationMap.zip (40个子文件)
LocationMap
AndroidManifest.xml 865B
res
layout
main.xml 1KB
drawable-ldpi
icon.png 2KB
drawable-mdpi
pos.gif 762B
icon.png 4KB
drawable-hdpi
icon.png 6KB
values
strings.xml 326B
proguard.cfg 1KB
src
org
crazyit
map
PosOverLay.java 1013B
LocationMap.java 4KB
bin
classes
org
crazyit
map
LocationMap$1.class 2KB
R.class 510B
R$layout.class 385B
R$attr.class 331B
R$id.class 460B
LocationMap$2.class 1KB
LocationMap.class 4KB
R$string.class 535B
PosOverLay.class 1KB
R$drawable.class 418B
res
drawable-ldpi
icon.png 2KB
drawable-mdpi
icon.png 3KB
drawable-hdpi
icon.png 6KB
LocationMap.apk 22KB
org
crazyit
map
LocationMap$1.class 2KB
R.class 510B
R$layout.class 385B
R$attr.class 331B
R$id.class 541B
LocationMap$2.class 1KB
LocationMap.class 3KB
R$string.class 623B
PosOverLay.class 1KB
R$drawable.class 418B
classes.dex 7KB
resources.ap_ 16KB
.classpath 288B
assets
project.properties 376B
.project 847B
gen
org
crazyit
map
R.java 1KB
共 40 条
- 1
Missing311
- 粉丝: 3
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页