游戏开发5_02 定位2

package wyf.ytl;
import android.content.Context;//引入相关类
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
public class Sample_5_4 extends MapActivity {
MapView myMapView = null;//声明MapView的引用
MapController myMapController = null;//声明myMapController的引用
LocationManager mLocationManager = null;
double jingDu = 116.46;
double weidu = 39.92;
public final LocationListener mLocationListener = new LocationListener(){
public void onLocationChanged(Location location){
weidu = location.getLatitude();
jingDu = location.getLongitude();
setGeoPoint();//设置地图的经纬度
}
public void onProviderDisabled(String provider){//空实现
}
public void onProviderEnabled(String provider){//空实现
}
public void onStatusChanged(String provider, int status, Bundle extras){//空实现
}
};
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myMapView = (MapView) this.findViewById(R.id.myMapView);//得到myMapView的引用
myMapController = myMapView.getController();//获得MapController
setGeoPoint();//设置地图的经纬度
//取得系统LOCATION服务
mLocationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
//监听Location更改时的事件,更新MapView
mLocationManager.requestLocationUpdates(mLocationManager.GPS_PROVIDER, 2000, 10, mLocationListener);
}
public void setGeoPoint(){//设置地图的经纬度的方法
GeoPoint gp = new GeoPoint((int)(weidu*1E6), (int)(jingDu*1E6));
myMapController.animateTo(gp);//设置经纬度
myMapController.setZoom(18);//设置放大等级
}
protected boolean isRouteDisplayed() {
return false;
}
}


<?xml version="1.0" encoding="utf-8"?><!-- XML的版本以及编码方式 -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
><!--定义一个线性布局 -->
<com.google.android.maps.MapView
android:id="@+id/myMapView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:apiKey="0TaUmOAuP1gmqcGMMUDZahZeDUfmUaqkTPT91kw"
/><!--在线性布局中添加MapView用来显示地图 -->
</LinearLayout>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值