0
votes

How to find out latitude and longitude from the address...

Here's the code for the spinner where we get the value of address

       landmark_addprod.setOnItemSelectedListener(new OnItemSelectedListener(){
        public void onItemSelected(AdapterView<?> parent, View view, int pos,long id)
        {
            // ListView Clicked item value
            itemValue_landmark = (String) landmark_addprod.getItemAtPosition(pos);
        }

and here get the value of city

            public void onItemSelected(AdapterView<?> parent, View view, int pos,long id)
            {
                itemPosition_city = pos;

                  // ListView Clicked item value
                   itemValue_city = (String) city_addprod.getItemAtPosition(pos);
            }

So how to concatenate the address and city values and how to find out lat longitude from that???

also used--

                Geocoder coder = new Geocoder(addproducts.this);
             try 
                {
            ArrayList<Address> adresses = (ArrayList<Address>) coder.getFromLocationName(itemValue_landmark + itemValue_city, 1);
            for(Address add : adresses){
                    longitude = add.getLongitude();
                    latitude = add.getLatitude();
                } 
            }
        catch (IOException e) {
                e.printStackTrace();
            }

but get the latitude and longitude 0.0

1

1 Answers

0
votes

This previous question may of use to you. Check it out here. Used this method before and it works nicely!