在 android 中放置带有 google 地图的标记商店(特定商店名称)
place markers stores(pirtucular store name) with google maps in android
您好,我想在靠近用户当前位置的所有购物者停靠商店上放置标记。我正在使用以下代码
目前我只有 2 个位置,我想设置一些半径并且还想显示所有商店。
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], 10);
} 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));
}
}
}
但无法获得相关结果。帮帮我。
您应该查看 nearby search 的 Places API 网络服务。
为了让您的生活更轻松,您还可以使用位于 github:
的 Google 地图服务的 Java 客户端
https://github.com/googlemaps/google-maps-services-java
遵循 Java 客户端库的文档,您应该能够搜索附近地点的给定位置和半径。
希望对您有所帮助!
您好,我想在靠近用户当前位置的所有购物者停靠商店上放置标记。我正在使用以下代码
目前我只有 2 个位置,我想设置一些半径并且还想显示所有商店。
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], 10);
} 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));
}
}
}
但无法获得相关结果。帮帮我。
您应该查看 nearby search 的 Places API 网络服务。
为了让您的生活更轻松,您还可以使用位于 github:
的 Google 地图服务的 Java 客户端https://github.com/googlemaps/google-maps-services-java
遵循 Java 客户端库的文档,您应该能够搜索附近地点的给定位置和半径。
希望对您有所帮助!