get current position location android

前端 未结 3 1463
小蘑菇
小蘑菇 2020-12-10 20:17

Location.java

package com.localisation;

import java.io.IOException;
import java.util.List;

import android.app.Activity;
import android.app.AlertDialog;
imp         


        
相关标签:
3条回答
  • 2020-12-10 20:51

    I am using this code to get the Latitude and longitude of current location:

    LocationManager locManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
    
    locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,1000L,500.0f, locationListener);
    Location location = locManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    
    double latitude=0;
    double longitude=0;
    latitude = location.getLatitude();
    longitude = location.getLongitude();
    
    0 讨论(0)
  • 2020-12-10 20:51

    I'm not sure if you are asking in general, "how do I get the gps location?" or more specific "what's wrong with this code".

    If its general- this appears in How do I get the current GPS location programmatically in Android?. Also, I suggest you be careful with the getLastKnownLocation method. The last location can be horribly out of date. I also suggest you start polling gps before you actually need it, it can sometimes take a few seconds (or more) to get your first gps reading.

    If its specific- maybe explain what problems you're having?

    0 讨论(0)
  • 2020-12-10 20:55

    we will create an Android application which will display current location in Google Maps using Google Maps Android API V2.

    Since the Google Map is displayed using SupportMapFragment, this application can run in Android API Level 8 or above. In order to use MapFragment for Google Maps, we need Android device with API level 12 or above.

    This application is developed in Eclipse 4.2.1 with ADT plugin ( 21.0.0 ) and Android SDK ( 21.0.0 ). This application is tested in a real Android Phone with Android ( 2.3.6 ). An alternative method for this application is available at Showing current location using OnMyLocationChangeListener in Google Map Android API V2

    Download code

    0 讨论(0)
提交回复
热议问题