从应用程序启动谷歌地图 - Android

时间:2013-03-01 18:07:56

标签: android google-maps

我想在我的应用中使用Google地图 - 从我的应用中启动Google地图。我创建了这段代码(在这个论坛上有不同的问题):

String uri = String.format(Locale.ENGLISH, "geo:%f,%f", latitude, longitude);
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
FinishActivity.this.startActivity(intent);

它工作得很好 - 它启动谷歌地图,但没有任何标签(这个绿色指针带有“A”)并且Zoom非常大。我该怎么改变它?有什么方法可以显示它们之间的两个点和路线吗?

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

    public class MapRouteActivity extends MapActivity {    
          LinearLayout linearLayout;
   MapView mapView;
     private Road mRoad;    
  @Override
  public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);    
new Thread() {
@Override
public void run() {
 double fromLat = 49.85, fromLon = 24.016667; 
 double toLat = 50.45, toLon = 30.523333;
 String url = RoadProvider
  .getUrl(fromLat, fromLon, toLat, toLon);
 InputStream is = getConnection(url);
 mRoad = RoadProvider.getRoute(is);
 mHandler.sendEmptyMessage(0);
 }
 }.start();
 }

 Handler mHandler = new Handler() {
 public void handleMessage(android.os.Message msg) {
  TextView textView = (TextView) findViewById(R.id.description);
  textView.setText(mRoad.mName + " " + mRoad.mDescription);
  MapOverlay mapOverlay = new MapOverlay(mRoad, mapView);
  List<Overlay> listOfOverlays = mapView.getOverlays();
   listOfOverlays.clear();
   listOfOverlays.add(mapOverlay);
   mapView.invalidate();
    };
    };

 private InputStream getConnection(String url) {
 InputStream is = null;
  try {
  URLConnection conn = new URL(url).openConnection();
  is = conn.getInputStream();
  } catch (MalformedURLException e) {
  e.printStackTrace();
   } catch (IOException e) {
   e.printStackTrace();
   }
  return is;
  }    
   @Override
 protected boolean isRouteDisplayed() {
  return false;
  }
 }

查看(https://code.google.com/p/j2memaprouteprovider/source/browse/trunk/J2MEMapRouteAndroidEx/src/org/ci/geo/route/android/MapRouteActivity.java

上的完整代码

地图的缩放级别

MapController myMC myMapView.getController();

myMC.setZoom(int value);