0

I am developing an app in which i have to get the latituide and longitude details and i am getting the details but when i put that details in http://itouchmap.com/latlong.html i get wrong location.My code is as follows:

 Log.v("----------","mlocManager");
    mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
    mlocListener = new MyLocationListener();
    mlocManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 300000, 40,  mlocListener);

and location class is as follows:

public class MyLocationListener implements LocationListener
 {
    public void onLocationChanged(final Location loc)
    {


        try 
        {

        System.out.println("............ ..............................Location changedin 11");
        latitude = loc.getLatitude();// here the app is getting lat
        longitude = loc.getLongitude(); // and here long
        altitude=loc.getAltitude();

        String s= Double.toString(latitude);
        String lat=s.substring(0, 2);
        String lat1=s.substring(3, 5);
        String lat2=s.substring(5, 7);
        String lat3=s.substring(7, 9);

          finallat=lat+(char) 0x00B0 +lat1+"'"+lat2+"."+lat3+"''";
        System.out.println("finallat"+finallat);


        String s1= Double.toString(longitude);
        String longt=s1.substring(0, 2);
        String longt1=s.substring(3, 5);
        String longt2=s.substring(5, 7);
        String longt3=s.substring(7, 9);

         finalllong=longt+(char) 0x00B0 +longt1+"'"+longt2+"."+longt3+"''";
        System.out.println("finallong:"+finalllong);

        System.out.println("newwwwww"+(char) 0X00B1);

        loc.getAccuracy();
        System.out.println("altitude   : "+loc.hasAltitude());



        latitudee=(TextView)findViewById(R.id.latitudee);
        latitudee.setText(finallat);

        longitudee=(TextView)findViewById(R.id.longitudee);
        longitudee.setText(""+finalllong);

        accuracyy=(TextView)findViewById(R.id.accuracyy);
        accuracyy.setText(""+(char) 0X00B1+loc.getAccuracy()+"m");
        System.out.println("acc : "+""+(char) 0X00B1+loc.getAccuracy()+"m");

        System.out.println("alti:"+altitude);



          }

    @Override
    public void onProviderDisabled(String provider) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onProviderEnabled(String provider) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
        // TODO Auto-generated method stub

    }
  • what location you are getting on map ? – Lucifer Jan 05 '12 at 06:17
  • Arjun ,Suppose the exact location is 30.73 and so on but i am getting 30.7276 and so on –  Jan 05 '12 at 06:19
  • ok, so what result you are expecting at this point ? – Lucifer Jan 05 '12 at 06:21
  • I suspect that all the formatting you're doing on the lat & long is munging something up. What happens if you examine the raw values (in the debugger, for instance) and map those? – elijah Jan 05 '12 at 06:28
  • why are you doing this ? String longt=s1.substring(0, 2); String longt1=s.substring(3, 5); String longt2=s.substring(5, 7); String longt3=s.substring(7, 9); – Sujit Jan 05 '12 at 06:30
  • As mentioned, it could be the formatting. But one other thing to consider is that the NETWORK_PROVIDER usually provides a very inaccurate location. Often 2000 meters or larger. If you're connected to Wi-fi, then my experience is that it's about 55 meters, but NETWORK_PROVIDER based on the cell towers is VERY inaccurate. – Reed Jan 05 '12 at 06:33
  • Jakar , then what should i use to get accurate location? –  Jan 09 '12 at 06:08
  • Arjun, i am accurate location like 30.73123 but not 30.7276 –  Jan 09 '12 at 06:09
  • Surjit, i am using substring for UI purpose only –  Jan 09 '12 at 06:10

1 Answers1

0

Use GPS provider instead of Network provider and it do works and my code is as follows:

mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
mlocListener = new MyLocationListener();
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 300000, 40,  mlocListener);