WEB开发网
开发学院手机开发Android 开发 Android地图开发中的地理编码与地理反编码 阅读

Android地图开发中的地理编码与地理反编码

 2010-10-19 20:17:53 来源:WEB开发网   
核心提示:地理反编码,其中MapOverlay为地图图层上的叠加图层,Android地图开发中的地理编码与地理反编码(4),用于标识的显示以及点击事件的捕捉,class MapOverlay extends com.google.android.maps.Overlay{@Overridepublic boolean draw(

地理反编码,其中MapOverlay为地图图层上的叠加图层,用于标识的显示以及点击事件的捕捉。

class MapOverlay extends com.google.android.maps.Overlay

{

@Override

public boolean draw(Canvas canvas, MapView mapView,

boolean shadow, long when)

{

//...

}

@Override

public boolean onTouchEvent(MotionEvent event, MapView mapView)

{

//---when user lifts his finger---

if (event.getAction() == 1) {

GeoPoint p = mapView.getProjection().fromPixels(

(int) event.getX(),

(int) event.getY());

Geocoder geoCoder = new Geocoder(

getBaseContext(), Locale.getDefault());

try {

List

addresses = geoCoder.getFromLocation(

p.getLatitudeE6() / 1E6,

p.getLongitudeE6() / 1E6, 1);

String add = "";

if (addresses.size() > 0)

{

for (int i=0; i

i++)

add += addresses.get(0).getAddressLine(i) + " ";

}

Toast.makeText(getBaseContext(), add, Toast.LENGTH_SHORT).show();

}

catch (IOException e) {

e.printStackTrace();

}

return true;

}

else

return false;

}

}

class MapOverlay extends com.google.android.maps.Overlay

{

@Override

public boolean draw(Canvas canvas, MapView mapView,

boolean shadow, long when)

{

//...

}

@Override

public boolean onTouchEvent(MotionEvent event, MapView mapView)

{

//---when user lifts his finger---

if (event.getAction() == 1) {

GeoPoint p = mapView.getProjection().fromPixels(

(int) event.getX(),

(int) event.getY());

Geocoder geoCoder = new Geocoder(

getBaseContext(), Locale.getDefault());

try {

List

addresses = geoCoder.getFromLocation(

p.getLatitudeE6() / 1E6,

p.getLongitudeE6() / 1E6, 1);

String add = "";

if (addresses.size() > 0)

{

for (int i=0; i

i++)

add += addresses.get(0).getAddressLine(i) + " ";

}

Toast.makeText(getBaseContext(), add, Toast.LENGTH_SHORT).show();

}

catch (IOException e) {

e.printStackTrace();

}

return true;

}

else

return false;

}

}

上一页  1 2 3 4 5  下一页

Tags:Android 地图 开发

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接