Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 传递到自定义视图的标记文本的值错误_Android_Json_Google Maps_Android Asynctask_Android Location - Fatal编程技术网

Android 传递到自定义视图的标记文本的值错误

Android 传递到自定义视图的标记文本的值错误,android,json,google-maps,android-asynctask,android-location,Android,Json,Google Maps,Android Asynctask,Android Location,我正在开发一个显示地图的android应用程序。加载时,它会显示一些地址并为它们设置标记 当我单击任何标记时,它应该在自定义视图中显示一个值。但是从json解析器接收的自定义文本会得到一个空值。当我再次单击标记时,它会设置正确的值 当我点击第二个标记时,它会显示第一个标记值。当我再次单击第二个标记时,它会显示正确的值。这一进程仍在继续 这是我的密码: private class GeocoderTask extends AsyncTask<String, Void, List<

我正在开发一个显示地图的android应用程序。加载时,它会显示一些地址并为它们设置标记

当我单击任何标记时,它应该在自定义视图中显示一个值。但是从json解析器接收的自定义文本会得到一个空值。当我再次单击标记时,它会设置正确的值

当我点击第二个标记时,它会显示第一个标记值。当我再次单击第二个标记时,它会显示正确的值。这一进程仍在继续

这是我的密码:

    private class GeocoderTask extends AsyncTask<String, Void, List<Address>>{
        private Context mainContxt;
        Geocoder geocoder;
        public GeocoderTask(Context con){
        mainContxt=con;

        } 

        @Override
        protected List<Address> doInBackground(String... locationName) {
             Geocoder geocoder = new Geocoder(mainContxt);
                List<Address> addresses = null;
                try {
                    addresses = geocoder.getFromLocationName(locationName[0],1);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                return addresses;
        }


        @Override
        protected void onPostExecute(List<Address> addresses) { 

       for(int i=0;i<addresses.size();i++){             

                Address address = (Address) addresses.get(i);
                latLng = new LatLng(address.getLatitude(), address.getLongitude());

                String addressText = String.format("%s, %s",
                        address.getMaxAddressLineIndex() > 0 ? address.getAddressLine(0) : "",
                        address.getCountryName());

                markerOptions = new MarkerOptions();
                markerOptions.position(latLng);
                markerOptions.title(addressText);
                if(i==0)    {
                    googleMap.animateCamera(CameraUpdateFactory.zoomBy(14),2000,null);
                    googleMap.animateCamera(CameraUpdateFactory.newLatLng(latLng)); 
                }
                googleMap.addMarker(markerOptions);

            }
       googleMap.setOnMarkerClickListener(new OnMarkerClickListener() {

            @Override
            public boolean onMarkerClick(Marker marker_address) {
                    location=marker_address.getTitle();
                    Toast.makeText(getApplicationContext(),location, Toast.LENGTH_LONG).show();
                new LoadSingleProperty().execute();
                //new LoadImage().execute();
                return false;

            }
        });

        googleMap.setInfoWindowAdapter(new InfoWindowAdapter() {
            @Override
            public View getInfoWindow(Marker arg0) {
                return null;
            }
            @Override
            public View getInfoContents(Marker marker) {

                View myContentView = getLayoutInflater().inflate(
                        R.layout.custom_marker, null);
                tempnew_price=getPrice(temptotal_price+"" +email);
                TextView tvTitle = ((TextView) myContentView
                        .findViewById(R.id.title));
               // tvTitle.setText(location);
                tvSnippet = ((TextView) myContentView
                        .findViewById(R.id.snippet));

               ivProperty = ((ImageView) myContentView
                        .findViewById(R.id.image_property));

               tvTitle.setText(tempcovered_area+ " "+tempnew_price+System.getProperty("line.separator")+templocation);

               tvSnippet.setText("A "+ tempbedroom + " "+tempproperty_type);


              // new LoadImage().execute();
            ivProperty.setImageBitmap(bmp); 
                    return myContentView;


            }
        });
        googleMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {

            @Override
            public void onInfoWindowClick(Marker arg0) {
                Intent intent = new Intent(getBaseContext(),
                        search_property_activity.class);
                intent.putExtra("Email", email);
                startActivity(intent);
            }
        });
    }
    }
私有类GeocoderTask扩展异步任务{
私人语境;
地理编码器;
公共地理编码任务(上下文con){
mainContxt=con;
} 
@凌驾
受保护列表doInBackground(字符串…位置名称){
Geocoder Geocoder=新的Geocoder(mainContxt);
列表地址=空;
试一试{
addresses=geocoder.getFromLocationName(locationName[0],1);
}捕获(IOE异常){
e、 printStackTrace();
}
返回地址;
}
@凌驾
受保护的void onPostExecute(列表地址){
对于(int i=0;i 0?地址。getAddressLine(0):“”,
address.getCountryName());
markerOptions=新的markerOptions();
标记选项位置(板条);
标记选项。标题(地址文本);
如果(i==0){
googleMap.animateCamera(CameraUpdateFactory.zoomBy(14),2000,空);
googleMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
}
googleMap.addMarker(markerOptions);
}
setOnMarkerClickListener(新的OnMarkerClickListener()){
@凌驾
公共布尔onMarkerClick(Marker\u地址){
location=marker_address.getTitle();
Toast.makeText(getApplicationContext(),location,Toast.LENGTH_LONG.show();
新建LoadSingleProperty().execute();
//新建LoadImage().execute();
返回false;
}
});
setInfoWindowAdapter(新的InfoWindowAdapter(){
@凌驾
公共视图getInfoWindow(标记arg0){
返回null;
}
@凌驾
公共视图getInfoContents(标记器){
查看myContentView=getLayoutInflater()。充气(
R.layout.custom_标记,空);
tempnew\u price=getPrice(试探总价格+“”+电子邮件);
TextView tvTitle=((TextView)myContentView
.findviewbyd(R.id.title));
//tvTitle.setText(位置);
tvSnippet=((文本视图)myContentView
.findviewbyd(R.id.snippet));
ivProperty=((图像视图)myContentView
.findviewbyd(R.id.image_属性));
tvTitle.setText(tempcovered_area+“”+tempnew_price+System.getProperty(“line.separator”)+模板定位);
tvSnippet.setText(“A”+tempDoomy+“”+tempproperty_类型);
//新建LoadImage().execute();
设置图像位图(bmp);
返回myContentView;
}
});
setOnInfoWindowClickListener(新的OnInfoWindowClickListener(){
@凌驾
公用无效信息窗口单击(标记arg0){
意向意向=新意向(getBaseContext(),
搜索属性(活动类);
意向。额外(“电子邮件”,电子邮件);
星触觉(意向);
}
});
}
}
这是我的loadsingle类编码

    class LoadSingleProperty extends AsyncTask<String, String, String> {
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(MainActivityMap.this);
            pDialog.setMessage("Loading Location. Please wait...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(false);
            pDialog.show();
        }
        protected String doInBackground(String... args) {
                List<NameValuePair> params = new ArrayList<NameValuePair>();
            if(location!=null && !location.equals("")){
                params.add(new BasicNameValuePair("Location", location));
                json= jsonParser.makeHttpRequest(url_loc_address, "GET", params);
            }
            Log.d("MyLocation: ", json.toString());

            try {
                int success = json.getInt(TAG_SUCCESS);

                if (success == 1) {
                    address = json.getJSONArray(TAG_ALL_ADDRESS);
                    //for (int i = 0; i < address.length(); i++) {
                        JSONObject c = address.getJSONObject(0);
                        templocation = c.getString(TAG_LOCATION);
                        tempcovered_area=c.getString(TAG_COVERED_AREA);
                        temptotal_price=c.getString(TAG_Total_Price);

                        tempbedroom=c.getString(TAG_BEDROOM);
                        tempproperty_type=c.getString(TAG_PROPERTY_TYPE);
                        tempemail=c.getString(TAG_EMAIL);
                        //} 
                } else {

                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
            return null;
        }



    protected void onPostExecute(String file_url) {
        pDialog.dismiss();  
        new GeocoderTask(MainActivityMap.this).execute(location);
        }


    }
class LoadSingleProperty扩展了AsyncTask{
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
pDialog=新建进度对话框(MainActivityMap.this);
pDialog.setMessage(“正在加载位置,请稍候…”);
pDialog.setUndeterminate(假);
pDialog.setCancelable(假);
pDialog.show();
}
受保护的字符串doInBackground(字符串…args){
List params=new ArrayList();
if(location!=null&&!location.equals(“”){
参数添加(新的BasicNameValuePair(“位置”,位置));
json=jsonParser.makeHttpRequest(url\u loc\u地址,“GET”,参数);
}
Log.d(“MyLocation:,json.toString());
试一试{
int success=json.getInt(TAG_success);
如果(成功==1){
address=json.getJSONArray(标记所有地址);
//for(int i=0;i
帮我,朋友们…提前谢谢

private class GeocoderTask extends AsyncTask<String, Void, List<Address>> {
    private Context mainContxt;
    Geocoder geocoder;

    public GeocoderTask(Context con) {
        mainContxt = con;

    }

    @Override
    protected List<Address> doInBackground(String... locationName) {
        Geocoder geocoder = new Geocoder(mainContxt);
        List<Address> addresses = null;
        try {
            addresses = geocoder.getFromLocationName(locationName[0], 1);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return addresses;
    }

    @Override
    protected void onPostExecute(List<Address> addresses) {

        for (int i = 0; i < addresses.size(); i++) {

            Address address = (Address) addresses.get(i);
            latLng = new LatLng(address.getLatitude(),
                    address.getLongitude());

            String addressText = String.format(
                    "%s, %s",
                    address.getMaxAddressLineIndex() > 0 ? address
                            .getAddressLine(0) : "", address
                            .getCountryName());

            markerOptions = new MarkerOptions();
            markerOptions.position(latLng);
            markerOptions.title(addressText);
            if (i == 0) {
                googleMap.animateCamera(CameraUpdateFactory.zoomBy(14),
                        2000, null);
                googleMap.animateCamera(CameraUpdateFactory
                        .newLatLng(latLng));
            }
            googleMap.addMarker(markerOptions);
        }
    }
}
使用另一个customeWindowAdapter或仅使用当前的customeWindowAdapter,并在'LoadSingleProperty'AsyncTask的onPostExecute()方法中设置它。。 这将解决这个问题。 圆周率
googleMap.setOnMarkerClickListener(new OnMarkerClickListener() {

    @Override
    public boolean onMarkerClick(Marker marker_address) {
        location = marker_address.getTitle();
        new LoadSingleProperty().execute();

        return false;

    }
});
class LoadSingleProperty extends AsyncTask<String, String, String> {
    Marker mMarker;

    public LoadSingleProperty(Marker marker){
      mMarker = marker;
    }

    .
    .
    .
}
new LoadSingleProperty(marker_address).execute();
mMarker.setTitle(c.getString(TAG_PROPERTY_TYPE));
tempproperty_type=c.getString(TAG_PROPERTY_TYPE);
InfoWindowAdapter infoWindowAdapter = new InfoWindowAdapter() {...
infoWindowAdapter.getInfoWindow(mMarker);