我已经创建了一个Android地图应用,根据用户当前位置加载最近的餐馆。并且已经有一个评级栏活动来输入评级,存储和检索数据库。现在我需要的是如何链接该特定餐厅的评级栏。有没有办法从标记和商店单独获取餐厅的名称,然后在评级栏数据库中。
答案 0 :(得分:0)
这取决于您的实施方式以及使用的API版本。
从here,我们看到一种方法可用于获取标记的标题。简单地使用getTitle()方法。
来自docs:
public String getTitle()
获取标记的标题。
返回包含标记标题的字符串。
因此,在标记对象上,您可以执行以下操作:
String title = marker.getTitle();
String snippet = marker.getSnippet();
答案 1 :(得分:0)
当用户点击标记时,你可以使用setonmarkerClickListener ..它会触发你的评级栏
googleMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker1) {
String name = marker1.getTitle();
String id = marker1.getId();
LatLng location = marker1.getPosition();
//create a custom dialog which contain ratingbar
//send the result to server
}
});
答案 2 :(得分:0)
//通过Geocoder获取地址
Geocoder geo = new Geocoder(getApplicationContext(), Locale.getDefault());
List<Address> addresses = geo.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
if (addresses.isEmpty()) {
//yourtextfieldname.setText("Waiting for Location");
markerOptions.title("Waiting for Location");
// markerOptions.title("Current Position");
}
else {
if (addresses.size() > 0) {
Address returnAddress = addresses.get(0);
String localityString = returnAddress.getLocality();
String city = returnAddress.getCountryName();
String region_code = returnAddress.getCountryCode();
String zipcode = returnAddress.getPostalCode();
StringBuilder str = new StringBuilder();
str.append(addresses.get(0).getAddressLine(1)+" "+addresses.get(0).getAddressLine(2) + " ");
str.append(localityString + " ");
str.append(city + " ");
str.append(region_code + " ");
str.append(zipcode + " ");
// yourtextfieldname.setText(addresses.get(0).getFeatureName() + ", " + addresses.get(0).getLocality() +", " + addresses.get(0).getAdminArea() + ", " + addresses.get(0).getCountryName());
markerOptions.title(str.toString());
//Toast.makeText(getApplicationContext(), "Address:- " + addresses.get(0).getFeatureName() + addresses.get(0).getAdminArea() + addresses.get(0).getLocality(), Toast.LENGTH_LONG).show();
}
}