我将在地图上获取用户点击的位置的纬度和经度,并对它们进行一些计算。 顺便说一句,我会说我正在使用模拟器,我无法访问手机,我必须在模拟器中运行它。 请帮帮我做什么!
答案 0 :(得分:0)
请详细说明您的需求,因为这个问题非常令人困惑。 您可以在谷歌地图上显示纬度和长值,我猜你是从网络服务或当前位置获得的。 要在模拟器上使用谷歌地图,您需要谷歌地图密钥。 让我知道你想要什么类型的帮助。
http://blogspot.fluidnewmedia.com/2009/04/displaying-google-maps-in-the-android-emulator/ 以上链接ID很适合。
答案 1 :(得分:0)
您应该澄清您正在使用的内容(Google API或地图图片),我假设您使用的是Java for Android,如果您使用的是图片,则可以使用
onTouchEvent
找到您的坐标,然后将它们作为经度和纬度返回到屏幕上
只要你在地图上知道自己的经度和纬度......请在你的问题中更具描述性。
public boolean onTouchEvent(MotionEvent event){
int action = event.getAction();
int x = event.getX()
int y = event.getY();
return yourBoolean;
}
答案 2 :(得分:0)
We can not get the current lat and long values in the emulator up to my knowledge. You have to put them your self.Correct me if I am wrong but this is true for that you have to use the real device.
I think this code will help you.Give try on device and let me know.
public class Google_maps extends MapActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_google_maps);
MapView mapview=(MapView)findViewById(R.id.mapView);
mapview.setBuiltInZoomControls(true);
MapOverlay mapOverlay = new MapOverlay();
List<Overlay> listOfOverlays = mapview.getOverlays();
listOfOverlays.clear();
listOfOverlays.add(mapOverlay);
mapview.invalidate();
}
class MapOverlay extends Overlay
{
@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());
Toast.makeText(getBaseContext(),
p.getLatitudeE6() / 1E6 + "," +
p.getLongitudeE6() /1E6 ,
Toast.LENGTH_SHORT).show();
}
return false;
}
}
@Override
protected boolean isRouteDisplayed() {
return false;
}}