0
我是新來的機器人,我試圖從URL讀取json文件,並獲取緯度和長度,並 將值賦予標記並將其顯示在地圖中,我的問題如何獲取lan,long,after閱讀json的內容? 這裏是在URL JSON的URL數據 JSON數據從Json URL中讀取Lan,Long並分配lat和long來映射標記?
{"properties":{"1":{"name":"Villa For
Sale","lat":"35.2474962142","lng":"-91.3480163353","price":"$100,000","image1":"http:\/\/wpl28.realtyna.com\/theme28\/wp-content\/uploads\/WPL\/91\/thimg_12_800x420.jpg","image2":"http:\/\/wpl28.realtyna.com\/theme28\/wp-content\/uploads\/WPL\/85\/thimg_2_800x420.jpg"},"2":{"name":"Apartment For Rent","lat":"35.9542249162","lng":"-101.21893164","price":"$40,000","image1":"ht
在android系統
我想要得到的緯度,經度和每個值assing向市場 地圖
//this method should get json data from onPostExecute(String s)
public void the_received_data(String received_data){
}
class Read_JSON extends AsyncTask<String ,String ,String >{
MainActivity mainActivity;
// class to handle reading json file
@Override
protected String doInBackground(String... params) {
HttpURLConnection connection =null;
BufferedReader data =null;
InputStream json_data;
try {
URL url = new URL(params[0]);
connection =(HttpURLConnection)url.openConnection();
connection.connect();
//holding the data into stream
json_data =connection.getInputStream();
data = new BufferedReader(new InputStreamReader(json_data));
StringBuffer stringBuffer = new StringBuffer();
//read the data from the bufferedredaer line by line
String line ="";
while((line =data.readLine()) != null){
stringBuffer.append(line);
}
return stringBuffer.toString();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
finally{
if(connection !=null){connection.disconnect();}
try {
if(data != null){
data.close();}
} catch (IOException e) {
e.printStackTrace();
}
}
return null; }
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
mainActivity.the_received_data(s);
}
}