user1025050
user1025050

Reputation:

android:implementing latitude-longitude

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

    }

Upvotes: 0

Views: 360

Answers (1)

user1025050
user1025050

Reputation:

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);

Upvotes: 0

Related Questions