我在 MYSQL DB 中有一组 lat 和 lon 值。我使用 JSON(从 PHP 代码中检索)在 android 应用程序中检索了它,并且能够在地图上显示这些位置。但我不知道如何在这些位置上放置标记。请帮我。
以下是我的代码:
try {
HttpClient client = new DefaultHttpClient();
URI website = new URI("http://192.168.1.15/latlonret1.php");
HttpGet request = new HttpGet();
request.setURI(website);
HttpResponse response = client.execute(request);
in = new BufferedReader(new InputStreamReader(response
.getEntity().getContent()));
StringBuffer sb = new StringBuffer("");
String l = "";
String nl = System.getProperty("line.separator");
while ((l = in.readLine()) != null) {
sb.append(l + nl);
}
in.close();
data = sb.toString();
// return data;
} catch (Exception e) {
Log.e("log_tag", "Error converting result " + e.toString());
}
try {
JSONArray jArray = new JSONArray(data);
for (int i = 0; i < jArray.length(); i++) {
JSONObject json_data = jArray.getJSONObject(i);
JSONObject json_data1 = jArray.getJSONObject(i);
returnString =json_data.getString("lat") + "\n";
returnString1 =json_data1.getString("lon") + "\n";
System.out.println(returnString);
System.out.println(returnString1);
}
Intent viewIntent =new Intent(Androidmap.this,Mapview.class);
Bundle bundle = new Bundle();
bundle.putString("stuff", returnString);
bundle.putString("stuff1", returnString1);
viewIntent.putExtras(bundle);
startActivity(viewIntent);
}