技术开发 频道

OPhone学习笔记 - 地图(4)

三、关键代码编写

  在原来的地图程序中,添加一个新的定位按钮,代码如下:

final Button where = (Button) findViewById(R.id.whereami);
where.setOnClickListener(
new Button.OnClickListener() {
public void onClick(View v){
mService
= (LocationManager)getSystemService(Context.LOCATION_SERVICE);
geoLatitude
= mService.getCurrentLocation("gps").getLatitude();
geoLongitude
= mService.getCurrentLocation("gps").getLongitude();
latText.setText(Double.toString(geoLatitude));
lngText.setText(Double.toString(geoLongitude));
}});

  即把获取的地理坐标显示到两个EditText中。

  在放大和缩小的按钮中,添加如下代码,并且在每次缩放后再放大倍数的edittext中显示当前倍数:

0
相关文章