android url访问KML路由
作者:互联网
我正在尝试使用以下网址在Google地图上的两点之间绘制路径,
在正常工作之前,但现在显示异常,
I/System.out(461): Unexpected end of document
doc为什么返回null?
我的代码在下面,
谢谢
解决方法:
这些链接可帮助您为地图编码:
MAPS Tutor
Maps Location
Maps Api
如果您只想要网址,则使用此:http://code.google.com/apis/kml/
这些是地图位置的完整源代码.
Android的
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;
}
}
在Google Code上查看关于J2MEMapRouteAndroidEx的完整代码
标签:kml,android,google-maps 来源: https://codeday.me/bug/20191013/1904428.html