在 Google 地图上绘制线条/路径
我很长一段时间都在忙于寻找如何在 HelloMapView 中的地图上的两个(GPS)点之间画一条线,但没有运气。
谁能告诉我该怎么做。
假设我使用扩展 MapView 的 HelloMapView。我需要使用叠加层吗?如果是这样,我是否必须重写覆盖层的 onDraw() 方法并在此处画一条线?我实际上尝试过这些事情但没有结果。
先感谢您!
I've been busy for a long time finding out how to draw a line between two (GPS) points on the map in HelloMapView but with no luck.
Could anyone please tell me how to do so.
Suppose I use the HelloMapView which extends MapView. Do I need to use overlays? If so do I have to override the onDraw() method of the overlay and draw a line here? I actually tried these things but with no result.
Thank you in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(13)
感谢您的帮助。我终于可以在地图上画一条线了。
我就是这样做的:
Thank you for your help. At last I could draw a line on the map.
This is how I done it:
对于那些实际上只想画一条简单线条的人 - 确实还有简短的版本。
来自 https://developers.google.com/maps /documentation/android/reference/com/google/android/gms/maps/model/Polyline
For those who really only want to draw a simple line - there is indeed also the short short version.
from https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/model/Polyline
这是完整的源代码,用于绘制从源纬度和经度到目的地纬度和经度的方向路径。我更改了上面的代码以适应纬度和经度,而不是源和目的地。
因此,任何通过 GPS 访问纬度和经度的人都可以获取从 GPS 设备到目的地坐标的方向。
感谢上述答案,我们可以做出这样的改变并获得路径方向。
希望它对其他 Stack Overflow 用户有帮助
This is full source code to draw direction path from source latitude and longitude to destination latitude and longitude. I have changed the above code to fit for latitude and longitude rather than source and destination.
So anyone who is accessing his latitude and longitude through his gps can get the direction from his gps device to the destination coordinates.
Thanks to above answers we could make such a change and get path direction.
Hope it helps for other Stack Overflow users
这也可以通过使用意图来完成:
This can be done by using intents too:
使用 Google Maps Android API v2 非常简单
只需复制 开发者文档
(当然你必须先初始化你的地图)
It is really easy with Google Maps Android API v2
Just copy the example from Developer documentation
(of course you have to init your map first)
是的,您需要使用叠加层。
您需要获取 MapView 的覆盖层并将新的覆盖层添加到其上。
您的类扩展了 Overlay,它是一个透明的画布,您可以在其中像任何其他画布一样在其上绘图。
您可以使用mapView.getProjection()来获取地图视图的投影。
...
更多信息在这里找到:http://blogscoped.com/archive/ 2008-12-15-n14.html
Yes you need to use overlays.
You need to get the MapView's overlays and add your new overlay onto it.
Your class extends Overlay, which is a transparent canvas in which you can draw on it like any other canvas.
You can use mapView.getProjection() to get projection of map view.
...
More info found here: http://blogoscoped.com/archive/2008-12-15-n14.html
您可以从 MapView 对象获取投影,并将其传递给 draw() 方法:
mapv.getProjection().toPixels(gP1, p1);
You can get the projection from the MapView object which is passed into the draw() method:
mapv.getProjection().toPixels(gP1, p1);
路由助手类
Route Helper class
只是我会在
mapview
中找到一些矩形,只是我们想改变绘画,因为我们喜欢EmptyOverlay.java
MapExampleActivity.java
MapOverlay.java
看到这个 http://n3vrax.wordpress.com/2011/08/13/drawing-overlays-on-android-地图视图/
just i will find draw with some rectangle in
mapview
just we want change paint as we likeEmptyOverlay.java
MapExampleActivity.java
MapOverlay.java
see this http://n3vrax.wordpress.com/2011/08/13/drawing-overlays-on-android-map-view/
只需从该网址获取路线并执行下一步...
在这里我将原点设置为德里的纬度和经度&目的地为昌迪加尔纬度经度
https://maps.googleapis.com/maps/api/directions/json?origin=28.704060,77.102493&destination=30.733315,76.779419&sensor=false&key="PUT您的地图 API 密钥”
Simply get route form this url and do next ...
here i have put origin as Delhi latitude and longitude & destination as chandigarh latitude longitude
https://maps.googleapis.com/maps/api/directions/json?origin=28.704060,77.102493&destination=30.733315,76.779419&sensor=false&key="PUT YOUR MAP API KEY"
这对我有用。通过这里提到的方法,我能够在 Google 地图 V2 上绘制折线。每当用户位置发生更改时,我都会绘制一条新线,因此折线看起来就像用户在地图上遵循的路径。
源代码位于。
Github:prasang7/eTaxi-Meter
请忽略此项目中与距离计算和用户界面相关的其他模块如果你对它们不感兴趣。
This worked for me. With the method mentioned here I was able to draw polylines on Google Maps V2. I drew a new line whenever the user location got changed, so the the polyline looks like the path followed by user on map.
Source code at.
Github: prasang7/eTaxi-Meter
Please ignore other modules of this project related to distance calculation and User Interface if you are not interested in them.