gpt4 book ai didi

android - 在mapview上绘制路线的最简单方法

转载 作者:行者123 更新时间:2023-11-29 16:10:26 26 4
gpt4 key购买 nike

我想显示用户当前位置和他在搜索 View 中输入的位置之间的路线。这是我的 onQueryTextSubmit 方法代码

@Override
public boolean onQueryTextSubmit(String query) {
// TODO Auto-generated method stub
try
{
if(direction.isChecked() == false)
{
gc = new Geocoder(this);

addresses = gc.getFromLocationName(query,5);
String add = "";
if (addresses.size() > 0)
{
p = new GeoPoint(
(int) (addresses.get(0).getLatitude() * 1E6),
(int) (addresses.get(0).getLongitude() * 1E6));
mc.animateTo(p);
mc.setZoom(9);
mapView.invalidate();

searchView.clearFocus();
}
else
{
Toast.makeText(this, " Location not found.",
Toast.LENGTH_LONG).show();
}
return true;
}
else
{
// draw a route between the locations
return true;
}
}
catch(IOException ex)
{

}

return false;
}

最简单的方法是什么? (示例将帮助我了解更多)

谢谢

最佳答案

一旦您有了目的地 GeoPoint,您就可以在这个地址中向 google 发出 http 请求:

String url = "http://maps.google.com/maps?f=d&hl=es&saddr="+ origin +"&daddr=" + destination + "&ie=UTF8&om=0&output=dragdir";

作为起点和终点(纬度、经度)点。

例如,this请求给你这个 json:

{tooltipHtml:" (86,4 km / 55 minutos)",polylines:[{id:"route0",points:"wa{uFt|kUoAkE??jDyE??uFuLqFaH??mAl@gAZ??q@[Yg@KwCBkATq@X[bCu@??tMsBrIuBrDoA~J}EbC{@pCy@dIeA`JBrDThd@nFpDRnTkAdBGVFhRyC`McA|KkAzCK|CP??lA~@NZHn@I~@Q`@c@\\[Hu@KYWUe@Gc@D{BnG}a@`Kcb@|A}JvAkOXmHDgFKcMMmDkBgW??SaCEoFBaCb@mH`AwGdE_Qh@sCf@}Db@yGFcFIqE]iGcAkLUyGB{K^aHf@_EfC_PtAqOlB}X|AiNrCyTnE{WjDqOtCqK~DoMhHoSvX}u@~KeYpI}VrSkk@zBiJ`@_Ct@oG`@mGPoGCcLMoDq@wHiCaSe@qE_BgTMuEEoIDsJxA_`@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B{DvRmW`BaC`AoBbAsCl@eCf@iDn@}G`@mC`AwD~AuDhJ{OdCuGfA{Ej@eEZwDzEgu@x@sJ^qBj@kBdD}HbAkDhEaX^gDJgC?iCKiCw@iIK_EL}Db@qDbAqD|@uBjOuVxIgQ~DsK|AuFpAaHt@_F`AqK^gL@yG_@u\\HeHNwEv@oKx@eHbDgPzDuNlAuD~F{O~BoF`AiBnBoCzFwF~CoDlBcEfAaD|Kc_@r@yBtAgD`AaBbHsJ|CsCrP_LpBwB`BqChAgDr@yDR}BhBs\\VuBx@kDlAyCdBkCdDqClQcHlC_B|CuDlJcQbA{AlAqA~_Ags@lSiSrBaCfOiWtVs]z`@_s@zMiVvAuBzPyTfRg[rBuD`B_EtCkIvKs]nCaHlEuIfHaMbMoRv[kd@lEqFfo@qp@|C{Cf@[bQsHrBoA~AsAbAqA|GsMtBiC|B_BlHwD`Au@vA{AnAmB|@wB|@eDbEmThAsEh@_BzAcDnKmP~z@}kA|AcBbDcCvFyBvSgGnBa@~TiGnNmC|DkB??xCoApDU|@UtAeAZm@\\gARkBQeK@i@^cC??pBkHvFy]Pm@ZCHQVuAAc@hAyC~@m@dBYzPq@??Jd@NJR?VSBi@pBq@l@e@d@e@jAoB\\_A\\_BnBePTCN[A[SWtIsr@Aq@VCLSAg@OQpDwX^kE??rAJrB]p@[tAuA",levels:"BBBBB?BB?BB???@??BB??????@???@???????BB??@???@????@???@????BB???@????@??????@??????@??@????@??A???@????@????@?????@????A?????@?????@???@???@?????@???A?@???@????@???@???@???A?????@????@??????????@??????@????@?????@???@???@?????BB??@???@??????@????@??@???@??A???@?????@????@?@??????????@???A???@?????@?????@???@?????@???????@??@???@???@????@???@????@???@???@??@????A????@????@????@?????@???@???@?????@??????@???@???@?????@??@???@????@???@?????@??????A???@???@??@??????@????@??@?@@???@???@???@??????@?@??@????BB????@????BB???????@??BB??????@???@????????????BB???B",numLevels:4,zoomFactor:16}]}

名称为 points 的字符串是您必须在 map 上绘制的折线。但是在绘制之前你必须解码它。看看here为了这个职责。

获得 GeoPoint 列表后,您可以将其绘制在 map 上。为此你需要一个 overlay如果您使用的是 google api v1。我建议您查看 api v2 .通过 GoogleMap 类和 PolylineOptions 中的 addPolyline 方法,可以更轻松地向 map 对象添加折线。

希望对您有所帮助。

关于android - 在mapview上绘制路线的最简单方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13911279/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com