关键词:
【中文标题】在谷歌地图android上显示位置【英文标题】:show location on google map android 【发布时间】:2015-05-11 12:46:12 【问题描述】:我有一个EditText
和一个Button
我想在地图中查找位置。我正在使用AsyncTask
执行这里是我对AsyncTask
类的调用。当我使用Toast
msg 时,它会显示我的位置,但在地图中它被强制关闭
new GeocoderTask().execute(location);
Toast.makeText(getApplicationContext(), location, Toast.LENGTH_LONG).show();
这是我的 GeocoderTask
类,用于在地图中显示位置
private class GeocoderTask extends AsyncTask<String, Void, List<Address>>
@Override
protected List<Address> doInBackground(String... locationName)
// Creating an instance of Geocoder class
Geocoder geocoder = new Geocoder(getBaseContext());
List<Address> addresses = null;
try
// Getting a maximum of 3 Address that matches the input text
addresses = geocoder.getFromLocationName(locationName[0], 3);
catch (IOException e)
e.printStackTrace();
return addresses;
@Override
protected void onPostExecute(List<Address> addresses)
if(addresses==null || addresses.size()==0)
Toast.makeText(getBaseContext(), "No Location found", Toast.LENGTH_SHORT).show();
// Clears all the existing markers on the map
googleMap.clear();
// Adding Markers on Google Map for each matching address
for(int i=0;i<addresses.size();i++)
Address address = (Address) addresses.get(i);
// Creating an instance of GeoPoint, to display in Google Map
latLng = new LatLng(address.getLatitude(), address.getLongitude());
String addressText = String.format("%s, %s",
address.getMaxAddressLineIndex() > 0 ? address.getAddressLine(0) : "",
address.getCountryName());
markerOptions = new MarkerOptions();
markerOptions.position(latLng);
markerOptions.title(addressText);
googleMap.addMarker(markerOptions);
// Locate the first location
if(i==0)
googleMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
但它不显示位置。
【问题讨论】:
请任何人帮助我..... 你有什么问题??? 我想在地图上搜索我的位置 你的代码在哪一行失败了?? 我在尝试搜索时没有任何错误显示强制关闭 【参考方案1】:假设你在new Geocoder(getBaseContext());
行有错误,所以建议你使用构造函数将Context
传递给AsyncTask
:
private class GeocoderTask extends AsyncTask<String, Void, List<Address>>
private Context mContext;
public GeoCoderTask(Context context)
super();
mContext = context;
@Override
protected List<Address> doInBackground(String... locationName)
// Creating an instance of Geocoder class
Geocoder geocoder = new Geocoder(mContext);
... ...
希望对您有所帮助!
【讨论】:
在谷歌地图上显示在线对象
...googlemap【发布时间】:2013-10-2211:45:07【问题描述】:我是Android开发新手,非常需要帮助。我正在为出租车招呼开发谷歌地图应用程序。我开发了原型,说明它将如何使用点对点技术。我的挑战:我可以在地图上显示用户和出租... 查看详情
如何在谷歌地图上显示当前街道位置?
】如何在谷歌地图上显示当前街道位置?【英文标题】:HowcanigetcurrentstreetlocationshowingonGoogleMap?【发布时间】:2011-12-2707:34:11【问题描述】:我希望我的网站用户在Google地图上显示他们当前的街道位置。就像“Facebook签到”一样... 查看详情
显示很多需要在谷歌地图上进行地理编码的位置?
...布时间】:2015-08-2410:30:00【问题描述】:我正在编写一个Android应用程序,该应用程序将显示人们在Google地图上的网站上提供的“优惠”。我目前在数据库中有20-30k个报价,但它们是按地址而不是坐标存储的,因此在Google地图上... 查看详情
如何使用谷歌 API 客户端在谷歌地图 Android 中显示我的当前位置
】如何使用谷歌API客户端在谷歌地图Android中显示我的当前位置【英文标题】:HowtoshowmycurrentlocationinGoogleMapAndroidusinggoogleAPIclient【发布时间】:2016-02-1719:44:20【问题描述】:我想在地图上显示我的位置并放大它。我想使用GoolgeAPIC... 查看详情
java示例代码_在谷歌地图上显示当前位置附近的多个位置
java示例代码_在谷歌地图上显示当前位置附近的多个位置 查看详情
如何在谷歌地图上移动地图但将标记保留为android中的当前位置?
】如何在谷歌地图上移动地图但将标记保留为android中的当前位置?【英文标题】:howtomovesmapongooglemapbutkeepmarkerascurrentlocationinandroid?【发布时间】:2018-01-2204:59:37【问题描述】:我是android新手。我最近两天受苦了。我研究了很多... 查看详情
在谷歌地图上显示我的位置?
】在谷歌地图上显示我的位置?【英文标题】:Showingmylocationongooglemaps?【发布时间】:2015-02-1216:45:05【问题描述】:我从w3school获取他的代码。在这里,他们展示了如何将用户直接带到JavaScript代码中编写的地址。我不想将用户带... 查看详情
如何在谷歌地图android中显示当前位置的平滑移动
】如何在谷歌地图android中显示当前位置的平滑移动【英文标题】:Howtodisplaysmoothmovementofcurrentlocationingooglemapandroid【发布时间】:2018-03-0710:30:33【问题描述】:我正在实现一个地图导航应用程序。我每1000毫秒获取设备的当前位置... 查看详情
在谷歌地图上隐藏其他位置
】在谷歌地图上隐藏其他位置【英文标题】:Hideotherlocationongooglemap【发布时间】:2017-08-0902:48:29【问题描述】:如何在谷歌地图上隐藏其他酒店位置,我只想在我的项目中显示酒店位置。我尝试了许多不同的方式,比如能见度... 查看详情
如何拉取用户的当前位置并显示在谷歌地图 api 上? [复制]
】如何拉取用户的当前位置并显示在谷歌地图api上?[复制]【英文标题】:Howtopulluser\'scurrentlocationanddisplayongooglemapapi?[duplicate]【发布时间】:2018-01-2217:57:46【问题描述】:所以我要完成两件事1)拉取用户当前位置2)然后在谷歌地... 查看详情
如何在谷歌地图android上设置多个标记?
】如何在谷歌地图android上设置多个标记?【英文标题】:howtosetthemultiplemarkerongooglemapandroid?【发布时间】:2020-04-2214:26:50【问题描述】:我已经完成了具有多个位置的谷歌地图标记,并且我添加了一些带有医院名称、经度和纬度... 查看详情
Android - 我如何在谷歌地图中实现位置准确性
】Android-我如何在谷歌地图中实现位置准确性【英文标题】:Android-howIcanIachievelocationaccuracyinGoogleMap【发布时间】:2014-06-3023:29:32【问题描述】:我目前正在自学Android编程。我正要编写一个应用程序,它可以在不使用GPS的情况下... 查看详情
无法在谷歌地图android上动态设置多个标记
】无法在谷歌地图android上动态设置多个标记【英文标题】:UnabletosetMultiplemarkersdynamicallyongooglemapsandroid【发布时间】:2019-11-0807:53:39【问题描述】:我正在使用推送器从另一台设备接收位置。在我的地图中,我想从推送器数据中... 查看详情
在谷歌地图标记上显示信息
】在谷歌地图标记上显示信息【英文标题】:DisplayinformationonGoogleMapsmarker【发布时间】:2019-05-1716:33:40【问题描述】:我正在尝试获取保存在firebase实时数据库中的信息,并使用GoogleMapsAPI在地图上显示它们。这是我的火力基地这... 查看详情
如何使用 php-mysql,js 在谷歌地图上显示多个位置
】如何使用php-mysql,js在谷歌地图上显示多个位置【英文标题】:howtodisplayingmultiplelocationongooglemapusingphp-mysql,js【发布时间】:2018-03-1100:08:48【问题描述】:我必须尝试从db中获取lat,lng值并像这样将结果编码为json["name":"ahmedabad,GUJ",... 查看详情
在谷歌地图上画一个凸包
】在谷歌地图上画一个凸包【英文标题】:Drawaconvexhullonagooglemap【发布时间】:2016-11-0517:33:14【问题描述】:我是javascript新手,正在使用googlemapsAPIforjavascript。这是学校的任务,我们得到了一个工作脚本和一些php代码来显示地图... 查看详情
在谷歌地图上分享位置
】在谷歌地图上分享位置【英文标题】:SharinglocationongoogleMaps【发布时间】:2014-10-2703:40:38【问题描述】:我是androidLocationAPI和Maps的新手。我正在考虑制作一个可以用来分享朋友位置并在谷歌地图上找到他们的应用程序。市场... 查看详情
我想在谷歌地图上显示标记,如附图
】我想在谷歌地图上显示标记,如附图【英文标题】:Iwanttoshowmarkerongooglemapliketheattachedimage【发布时间】:2019-03-0503:15:00【问题描述】:我想在附加的图像中显示我当前的位置标记图标。【问题讨论】:检查这个:***.com/questions/... 查看详情