我在Google地图“我的地图”中创建了一个自定义地图。现在我想在Android设备上显示该地图,但不仅仅是将其作为网页打开,而是使用MapView或类似的smth显示它。我希望能够以我在地图上标记的地点为中心等。我的自定义地图是包含城市中所有加油站位置的地图。
有人可以指出我正确的方向或描述这一点的文章(我找不到任何东西)。
答案 0 :(得分:1)
我能理解的是,您需要创建可以在您的设备上显示的地图应用程序,并且您需要该地图上所有加油站的列表。 是写吗? 你可以通过在那个特定点上做标记来做到这一点,如果你知道那个地方的纬度和长度。
public class helloMap扩展MapActivity { /** 在第一次创建活动时调用。 * /
MapView mapView;
MapController mc;
GeoPoint p;
class MapOverlay extends com.google.android.maps.Overlay
{
@Override
public boolean draw(Canvas canvas, MapView mapView,
boolean shadow, long when)
{
super.draw(canvas, mapView, shadow);
//---translate the GeoPoint to screen pixels---
Point screenPts = new Point();
mapView.getProjection().toPixels(p, screenPts);
//---add the marker---
Bitmap bmp = BitmapFactory.decodeResource(
getResources(), R.drawable.pushpin);
canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null);
return true;
}
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
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapView);
LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom);
View zoomView = mapView.getZoomControls();
zoomLayout.addView(zoomView,
new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
mapView.displayZoomControls(true);
mc = mapView.getController();
String coordinates[] = {"22.70", "72.80"};
double lat = Double.parseDouble(coordinates[0]);
double lng = Double.parseDouble(coordinates[1]);
p = new GeoPoint(
(int) (lat * 1E6),
(int) (lng * 1E6));
mc.animateTo(p);
mc.setZoom(6);
mapView.invalidate();
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
} ...
如果你想存储位置,那么你可以成对地存储一个特定的加油站。
即使你不知道lat和long,你也可以使用GeoCoder Class来实现它。
这是回答你的问题