在 Android 中使用 Google 地图 API 显示当前位置和附近地点以及两地之间的路线

发布于 2024-12-20 07:20:30 字数 208 浏览 0 评论 0 原文

我需要在 Android 中使用 Google 地图 开发一个应用程序来定位我的当前位置,并且需要查找最近的位置

(例如:距离我当前位置最近的警察局。)

它应该接受我当前的位置,并且输出应该显示最近的位置。

谁能帮我提供一些建议、链接、教程来做到这一点?

I need to develop an application using Google Maps in Android to locate my current location and need to find nearest location.

(For example: Nearby police station from my current location.)

It should accept my current location and output should display nearest place.

Can anyone help me to give some suggestion,links,tutorial to do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

分开我的手 2024-12-27 07:20:30
  1. 首先阅读本教程 为了熟悉
    Android Google 地图以及 API 2< /a>.

  2. 要检索设备的当前位置,请参阅这个答案或者这个另一个答案API 2

  3. 然后,您可以使用 Google 地方信息获取您所在位置附近的地点
    API
    ,有关 Place Api 的使用,请参阅此博客

  4. 获取附近位置的地标后,使用这个
    带有源代码的博客
    ,通过 API 2 在地图上显示带有气球覆盖

  5. 您还有很好的示例来绘制地图上两点之间的路线
    在这些链接中查看 Link1< /a>Link2 和这个 < a href="https://stackoverflow.com/questions/3109158/how-to-draw-a-path-on-a-map-using-kml-file">很好的答案.

遵循这些步骤后,您将可以轻松地完成您的申请。唯一的条件是,您必须阅读并理解它,因为就像魔术一样,它不会在点击中完成。

  1. First go through this tutorial for getting familiar with
    Android Google Maps and this for API 2.

  2. To retrive the current location of device see this answer or this another answer and for API 2

  3. Then you can get places near by your location using Google Place
    API
    and for use of Place Api see this blog.

  4. After getting Placemarks of near by location use this
    blog with source code
    to show markers on map with balloon overlay with API 2.

  5. You also have great sample to draw route between two points on map
    look here in these links Link1 and Link2 and this Great Answer.

After following these steps you will be easily able to do your application. The only condition is, you will have to read it and understand it, because like magic its not going to be complete in a click.

战皆罪 2024-12-27 07:20:30

到目前为止有很多答案,它们都是 API 和教程的优秀指南。我想补充的一件事是,我使用以下方法计算出标记距我的位置有多远:

float distance = (float) loc.distanceTo(loc2);

希望这有助于完善您的问题的细节。它返回点之间距离(​​以米为单位)的粗略估计,对于消除可能太远的 POI 很有用 - 有助于整理您的地图吗?

Lots of answers so far, which are all excellent pointers to API's and tutorials. One thing I'd like to add is that I work out how far the markers are from my location using something like:

float distance = (float) loc.distanceTo(loc2);

Hope this helps refine the detail for your problem. It returns a rough estimate of distance (in m) between points, and is useful for getting rid of POI that might be too far away - good to declutter your map?

梦归所梦 2024-12-27 07:20:30

您可以在此处使用Google地图获取用户位置

获取您的位置(经度和纬度)后,您可以使用 google place api

此代码可以帮助您轻松获取位置,但这不是最好的方法。

locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
String bestProvider = locationManager.getBestProvider(criteria, true);
Location location = locationManager.getLastKnownLocation(bestProvider);  

You can use google map Obtaining User Location here!

After obtaining your location(longitude and latitude), you can use google place api

This code can help you get your location easily but not the best way.

locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
String bestProvider = locationManager.getBestProvider(criteria, true);
Location location = locationManager.getLastKnownLocation(bestProvider);  
巡山小妖精 2024-12-27 07:20:30

您有两种显示地图的选项

  1. 使用 Android 地图库来渲染地图
  2. 在 Web 视图中使用 Maps API V3

要显示经纬度周围的本地 POI,请使用 地点 API

You have two options for displaying the Map

  1. Use Maps Library for Android to render the Map
  2. Use Maps API V3 inside a web view

For showing local POIs around a Lat, Long use Places APIs

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文