使用 FusedLocationProviderApi 获取用户在后台服务上的位置 & Google Places API
Get user's location on background service using FusedLocationProviderApi & Google Places API
我当前的代码使用 FusedLocationProviderApi
来获取用户的当前 city/locality。此代码在我的 Service
:
try {
Geocoder gcd = new Geocoder(LocationUpdateService.this, Locale.getDefault());
List<Address> addresses = gcd.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
if (addresses.size() > 0)
{
txtStation.setText("Locality : " + addresses.get(0).getLocality() + " Sublocal : " + addresses.get(0).getSubLocality());
}
}catch (Exception e) {
Toast.makeText(LocationUpdateService.this, e.getMessage(), Toast.LENGTH_LONG).show();
}
但是我需要显示用户的更具体的地方(公交车站、加油站等),我想我必须使用Places API
。
如何将 Places API
集成到我当前的代码(使用 FusedLocationProviderApi
)?
我现在想的是用FusedLocationProviderApi
得到基本的latitude
和longitude
,然后用Places API
得到那些坐标。
请帮我me/show一些线索
非常感谢您的帮助
我当前的代码使用 FusedLocationProviderApi
来获取用户的当前 city/locality。此代码在我的 Service
:
try {
Geocoder gcd = new Geocoder(LocationUpdateService.this, Locale.getDefault());
List<Address> addresses = gcd.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
if (addresses.size() > 0)
{
txtStation.setText("Locality : " + addresses.get(0).getLocality() + " Sublocal : " + addresses.get(0).getSubLocality());
}
}catch (Exception e) {
Toast.makeText(LocationUpdateService.this, e.getMessage(), Toast.LENGTH_LONG).show();
}
但是我需要显示用户的更具体的地方(公交车站、加油站等),我想我必须使用Places API
。
如何将 Places API
集成到我当前的代码(使用 FusedLocationProviderApi
)?
我现在想的是用FusedLocationProviderApi
得到基本的latitude
和longitude
,然后用Places API
得到那些坐标。
请帮我me/show一些线索
非常感谢您的帮助