用于访问 KML 路由的 android url

标签 android google-maps kml

我正在尝试使用下面的 url 在谷歌地图上绘制两点之间的路径,

http://maps.google.com/maps?f=d&hl=en&saddr=13.005621,77.577531&daddr=13.005621,77.579531&ie=UTF8&0&om=0&output=kml

之前正常,现在显示异常,

 I/System.out(461): Unexpected end of document

doc 返回 null 为什么? 我的代码如下,

http://pastebin.com/XvR0rYdQ

谢谢

最佳答案

这些链接可帮助您为 map 编写代码:

MAPS Tutor
Maps Location
Maps Api

如果你只想要 url 那么使用这个:
http://code.google.com/apis/kml/

这些是 map 定位的完整源代码。


安卓

Android G1 screenshot http://img249.imageshack.us/img249/3336/androidmaproute.jpg

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;
 }
}

请参阅 J2MEMapRouteAndroidEx 上的完整代码在谷歌代码上

关于用于访问 KML 路由的 android url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8612524/

相关文章:

javascript - 我如何请求 Google Place API 返回地点的 ID?

python - Django django-location-field 缺少 API key

google-maps-api-3 - 设置 KML 图层透明度

google-maps - 我可以在 Google map 上显示一些 KML 吗?

image - kml Google Earth 中的动画地标图标?

java - 安卓.view.InflateException : Binary XML file: Error inflating class

在 windows 或 linux 上进行 Android 开发?

android - 在 Android 中使用 Firebase 在应用程序中添加 Youtube API

android - 无法从丢弃的 APK 中提取 Crashlytics 构建信息

android - 无法使用谷歌地图获取 map