Java 如何在谷歌地图android上显示多个标记
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19972476/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to show multiple marker on google map android
提问by Aoyama Nanami
i want to show location with multiple markers on google maps android, the problem is when i run my apps, it just show one location/marker, this is my code :
我想在谷歌地图 android 上显示多个标记的位置,问题是当我运行我的应用程序时,它只显示一个位置/标记,这是我的代码:
public class koordinatTask extends AsyncTask<String, String, String>
{
@Override
protected void onPreExecute() {
super.onPreExecute();
setProgressBarIndeterminateVisibility(true);
}
protected String doInBackground(String... args) {
String url = "http://absc?action=p04&prov="+link_kode+"&tipe=";
JSONArray data = null;
try {
JSONParser jParser = new JSONParser();
JSONObject json = jParser.getJSONFromUrl(url);
// Getting Array of data
data = json.getJSONArray(real_data);
System.out.println("realisasi done");
for(int i = 0; i < data.length(); i++){
JSONObject c = data.getJSONObject(i);
HashMap<String, String> map = new HashMap<String, String>();
HashMap<String, Double> map1 = new HashMap<String, Double>();
x_lat = c.getDouble(x_cord);
y_long = c.getDouble(y_cord);
label = c.getString(prov_label);
map1.put(x_cord, x_lat);
map1.put(y_cord, y_long);
map.put(prov_label, label);
ProvinsiList.add(map);
ProvinsiList.add(map1);
System.out.println(x_lat);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String file_url) {
LatLng MAP_PUPI = new LatLng(x_lat, y_long);
Marker Pupi = map.addMarker(new MarkerOptions().position(
new LatLng(x_lat, y_long)).title(label));
map.moveCamera(CameraUpdateFactory.newLatLngZoom(MAP_PUPI, 15));
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}
}
i don't know where's my fault, i hope somebody can help me to solve my problem, thank u verymuch
我不知道我的错在哪里,我希望有人能帮助我解决我的问题,非常感谢
采纳答案by Piyush
Use this:
用这个:
for (int i = 0; i < yourArrayList.size(); i++) {
double lati=Double.parseDouble(pins.get(i).latitude);
double longLat=Double.parseDouble(pins.get(i).longitude);
MAP.addMarker(new MarkerOptions().position(new LatLng(lati,longLat)).title(pins.get(i).pinname).snippet(pins.get(i).address));
}
Or you can also use this:
或者你也可以使用这个:
for(int pin=0; pin<pins.size(); pin++)
{
LatLng pinLocation = new LatLng(Float.parseFloat(pins.get(pin).latitude), Float.parseFloat(pins.get(pin).longitude));
Marker storeMarker = map.addMarker(new MarkerOptions()
.position(pinLocation)
.title(pins.get(pin).pinname)
.snippet(pins.get(pin).address)
);
}
where latitudeand longitudeis the String to which you have store in your arraylist with different name.....
其中纬度和经度是您在数组列表中以不同名称存储的字符串.....