0
我正在使用谷歌地圖api。在我的情況下,我通過php從MySQL接收緯度,經度和用戶名。我在一次收到所有用戶。我嘗試下面的代碼,它只給出一個marker.Plz指導我。不把它複製,因爲我嘗試了許多解決方案,但不工作的me.If u有沒有答案,請quit.Please Rec.class使用Maps API和獲取來自Mysql的座標不能獲得多個標記。爲什麼?
public class Rec extends AppCompatActivity{
private GoogleMap mMap;
JSONObject jsonObject = new JSONObject();
JSONArray result = new JSONArray();
ArrayList<HashMap<String,String>> list = new ArrayList<>();
private String latitude,longitude,user_name;
Button btn;
private ProgressDialog loading;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_rec_gps);
btn = (Button) findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
recGps();
}
});
}
private void recGps() {
loading = ProgressDialog.show(this, "Please wait ......", "fetching....", false, false);
String url = Config.URL_CARD_INFO;
StringRequest stringRequest = new StringRequest(url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
loading.dismiss();
showJSON(response);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(RecGPS.this, error.getMessage().toString(), Toast.LENGTH_LONG).show();
}
});
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}
private void showJSON(final String response) {
try {
jsonObject = new JSONObject(response);
result = jsonObject.getJSONArray(Config.TAG_JSON_ARRAY);
for (int i=0;i<result.length();i++) {
JSONObject collegeData = result.getJSONObject(i);
user_name=collegeData.getString(Config.TAG_NAME);
latitude = collegeData.getString(Config.TAG_ISSUE_DATE);
longitude = collegeData.getString(Config.TAG_Expiry_DATE);
HashMap<String,String> users = new HashMap<>();
users.put(Config.TAG_NAME,user_name);
users.put(Config.TAG_ISSUE_DATE,latitude);
users.put(Config.TAG_Expiry_DATE,longitude);
list.add(users);
}
} catch (JSONException e) {
e.printStackTrace();
}
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.getMaxZoomLevel();
for(int i=0;i<result.length();i++) {
mMap.addMarker(new MarkerOptions().position(new LatLng(Double.parseDouble(list.get(i).get(Config.TAG_ISSUE_DATE)), Double.parseDouble(list.get(i).get(Config.TAG_Expiry_DATE)))).icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)).title(list.get(i).get(Config.TAG_NAME)));
}
}
});
}
}
我知道看到downvote或重複的傷害,但請避免像** quit **這樣的詞。 –