简体   繁体   English

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

[英]Show Current Location and Nearby Places and Route between two places using Google Maps API in Android

I need to develop an application using Google Maps in Android to locate my current location and need to find nearest location . 我需要使用Android中的Google Maps开发一个应用程序来定位我当前的位置,并且需要找到最近的位置

(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? 有人可以帮我提出一些建议,链接,教程吗?

  1. First go through this tutorial for getting familiar with Android Google Maps and this for API 2 . 首先,通过本教程熟悉Android Google Maps和API 2

  2. To retrive the current location of device see this answer or this another answer and for API 2 要检索设备的当前位置,请参阅此答案或该其他答案以及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 . 然后,您可以使用Google Place API在您的位置附近找到地点,有关Place Api的使用,请参阅此博客

  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. 在按位置获取附近的地标后,请将该博客与源代码一起在带有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 . 您也有一个很棒的示例,可以在地图上的两个点之间绘制路线,请参见这些链接Link1Link2以及此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. 唯一的条件是,您将必须阅读并理解它,因为就像魔术一样,单击并不能完全完成。

Lots of answers so far, which are all excellent pointers to API's and tutorials. 到目前为止,有很多答案,这些都是指向API和教程的出色指针。 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? 它返回点之间的距离的粗略估计值(以m为单位),对于消除可能太远的POI很有用-可以使地图杂乱无章吗?

You can use google map Obtaining User Location here! 您可以在此处使用google map 获取用户位置

After obtaining your location(longitude and latitude), you can use google place api 获取位置(经度和纬度)后,您可以使用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);  

You have two options for displaying the Map 您有两个显示地图的选项

  1. Use Maps Library for Android to render the Map 使用Android的地图库渲染地图
  2. Use Maps API V3 inside a web view 在网络视图内使用Maps API V3

For showing local POIs around a Lat, Long use Places APIs 用于显示“长期使用的地方” API周围的本地POI

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM