Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,

I am getting multiple value for latitude and longitude from service and adding it to an arraylist for showing multiple marker on map for required latlng. But after adding it on map when i am clicking on any map for sending data to another activity i am getting only last index value for each. So i need help in sending particular marker data to another activity. Here is my code:-


Thanks

What I have tried:

/***************************************Authenticating**************************************/
    private void authenticateUser() {

        HttpPost request = new HttpPost(LOCATION_URL);
        request.setHeader("Accept", "application/json");
        request.setHeader("Content-type", "application/json");

        // Build JSON string
        JSONObject jsonObject = null;
        try {
            InputStream inputStream = null;

            // Fetching Data From DB
            DataBaseHelper myDBHelper = new DataBaseHelper(getActivity());
            myDBHelper.open();
            LoginTable loginTable= new LoginTable();
            loginTables= myDBHelper.getAllLoginRecord();
            if(loginTables.size()>0) {
                loginTable = loginTables.get(0);
                USER_ID=loginTable.userId;
                user_type=loginTable.usertype;
            }
            myDBHelper.close();

            result = "";
            JSONStringer userJson = new JSONStringer()
                    .object().key("latitude").value(latitude).key("longitute").value(longitude).key("user_id").value(USER_ID)
                    .key("distance").value(5).key("start_limit").value(0).key("end_limit").value(20)
                    .endObject();
            StringEntity stringEntity = null;
            stringEntity = new StringEntity(userJson.toString());
            request.setEntity(stringEntity);

            DefaultHttpClient httpClient = new DefaultHttpClient();

            HttpResponse response = httpClient.execute(request);

            int statusCode = response.getStatusLine().getStatusCode();
            if (statusCode == 200) {
                result = EntityUtils.toString(response.getEntity());

                if (result.contains("false")) {
                    AuthenticationStatus = true;
                    //a= result.substring(1,(result.length()-1)).replaceAll("\\\\","");
                    jsonObject = new JSONObject(result);
                    error = jsonObject.getString("error");
                    JSONArray jsonArray = jsonObject.getJSONArray("saloon_list");
                    int k = jsonArray.length();
                    for (int i = 0; i < k; i++) {
                        obj = new LatLngBean();
                        //write parsing code here.
                        JSONObject jsonObject1 = jsonArray.getJSONObject(i);
                        obj.Latitude = jsonObject1.getString("saloon_latitude");
                        obj.Longitude = jsonObject1.getString("saloon_longitute");
                        obj.Title = jsonObject1.getString("saloon_name");
                        obj.SaloonId=jsonObject1.getString("saloon_id");
                        obj.gender=jsonObject1.getString("gender");
                        obj.RunningToken = jsonObject1.getString("running_token");
                        obj.Inqueue = jsonObject1.getString("inquee");
                        obj.Ratings = jsonObject1.getString("rating");
                        obj.onlinestatus = jsonObject1.getString("saloon_online_status");
                        searchlist.add(obj);

                    }
                } else {
                    AuthenticationStatus = false;
                }
            } else {
                AuthenticationStatus = false;
            }
            Log.d("WebInvoke", result);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }


    // AsyncTask method for service execution
    private class AsyncLocation extends AsyncTask<String, Void, Void> {

        private ProgressDialog dialog;

        @Override
        protected void onPreExecute() {
            dialog = new ProgressDialog(getActivity());
            dialog.setTitle("Please Wait");
            dialog.setMessage("Loading...");
            dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
            dialog.setCancelable(false);
            dialog.setIndeterminate(false);
            dialog.show();
        }

        @Override
        protected Void doInBackground(String... params) {
            authenticateUser();
            return null;
        }

        @Override
        protected void onPostExecute(Void result1) {

            if (dialog.isShowing()) {
                dialog.dismiss();
            }

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

                // Calculating distance between saloon and user
                destlangitude = Double.valueOf(searchlist.get(i).Latitude);
                destlongitude = Double.valueOf(searchlist.get(i).Longitude);
                int Radius = 6371;
                double dLat = Math.toRadians(destlangitude - latitude);
                double dLon = Math.toRadians(destlongitude - longitude);
                double a = Math.sin(dLat / 2) * Math.sin(dLat / 2)
                        + Math.cos(Math.toRadians(latitude))
                        * Math.cos(Math.toRadians(destlangitude)) * Math.sin(dLon / 2)
                        * Math.sin(dLon / 2);
                double c = 2 * Math.asin(Math.sqrt(a));
                double valueResult = Radius * c;
                double km = valueResult / 1;
                DecimalFormat newFormat = new DecimalFormat("####");
                int kmInDec = Integer.valueOf(newFormat.format(km));
                double meter = valueResult % 1000;
                double finalmeter = meter * 1000;
                int meterInDec = Integer.valueOf(newFormat.format(meter));
                title = searchlist.get(i).Title;
                destination = new LatLng(destlangitude, destlongitude);

                if (km < 1) {
                    MarkerOptions destoptions = new MarkerOptions().title(title).snippet(String.format("%.2f", finalmeter) + "m").position(destination).anchor(.5f, .5f).draggable(true)
                            .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_shop_salon));
                    myMap.addMarker(destoptions);
                } else {

                    MarkerOptions destoptions = new MarkerOptions().title(title).snippet(String.format("%.2f", km) + "km").position(destination).anchor(.5f, .5f).draggable(true)
                            .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_shop_salon));
                    myMap.addMarker(destoptions);
                }

                String salStatus = searchlist.get(i).onlinestatus;

                if (salStatus.equals("1")) {

                    myMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
                        @Override
                        public void onInfoWindowClick(Marker marker) {

                            //myMap.setContentDescription(searchlist.get(i).Title);

                            Intent intent = new Intent(getActivity(), BookATime.class);
                            intent.putExtra("running_token", obj.RunningToken);
                            intent.putExtra("inquee", obj.Inqueue);
                            intent.putExtra("rating", obj.Ratings);
                            intent.putExtra("saloon_id", obj.SaloonId);
                            intent.putExtra("saloon_latitude", obj.Latitude);
                            intent.putExtra("saloon_longitute", obj.Longitude);
                            intent.putExtra("saloon_name", obj.Title);
                            intent.putExtra("gender", obj.gender);
                            startActivity(intent);

                        }
                    });
                }
            }
        }
    }
Posted
Updated 5-Jun-17 4:17am
v2
Comments
Richard MacCutchan 18-Apr-17 10:27am    
And somewhere in that code there is a problem?
Member 11642465 19-Apr-17 1:18am    
after clicking marker for sending data from one activity to another i am getting only last index value for each marker @ Richard MacCutchan

1 solution

Where is the code that executes when you click on a map (marker)? Where is the index value being obtained from?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900