是否有可能在android中获得被调用者位置

时间:2013-10-07 08:27:06

标签: android gps location telephonymanager

在我的Android应用程序中,我想获得被调用者的位置。当我打电话给他或她我想得到被叫的位置。有一些方法可用于获取呼叫者位置,但不能用于被呼叫者位置。其实我想用某种方法得到他或她的位置。做什么的方法(如果可能的话)。或建议任何解决方法。在此先感谢。我按位置经理获取我的位置如下。

//Variables used in method to get location
        LocationManager locationManager;
            // The minimum distance to change Updates in meters
                private final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 10; 
                // The minimum time between updates in milliseconds
                private final long MIN_TIME_BW_UPDATES = 1000;
                private boolean isGPSEnabled = false;
                boolean canGetLocation = false;
                // flag for network status
                boolean isNetworkEnabled = false;       
                private Location location; // location      
                private double latitude; // latitude
                private double longitude; // longitude    
        //the method is given below 
         private void getLocation(){
                locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);     
                if (locationManager!=null && locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {         
                    try {
                        locationManager = (LocationManager) getApplicationContext()
                                .getSystemService(LOCATION_SERVICE);
                        // getting GPS status
                        isGPSEnabled = locationManager
                                .isProviderEnabled(LocationManager.GPS_PROVIDER);

                        // getting network status
                        isNetworkEnabled = locationManager
                                .isProviderEnabled(LocationManager.NETWORK_PROVIDER);

                        if (!isGPSEnabled && !isNetworkEnabled) {
                            // no network provider is enabled
                        } else {
                            this.canGetLocation = true;
                            // First get location from Network Provider
                            if (isNetworkEnabled) {
                                locationManager.requestLocationUpdates(
                                        LocationManager.NETWORK_PROVIDER,
                                        MIN_TIME_BW_UPDATES,
                                        MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
                                Log.d("Network", "Network");
                                if (locationManager != null) {
                                    location = locationManager
                                            .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
                                    if (location != null) {
                                        latitude = location.getLatitude();
                                        longitude = location.getLongitude();
                                    }
                                }
                            }
                            // if GPS Enabled get lat/long using GPS Services
                            if (isGPSEnabled) {
                                if (location == null) {
                                    locationManager.requestLocationUpdates(
                                            LocationManager.GPS_PROVIDER,
                                            MIN_TIME_BW_UPDATES,
                                            MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
                                    Log.d("GPS Enabled", "GPS Enabled");
                                    if (locationManager != null) {
                                        location = locationManager
                                                .getLastKnownLocation(LocationManager.GPS_PROVIDER);
                                        if (location != null) {
                                            latitude = location.getLatitude();                                      longitude = location.getLongitude();
                                        }
                                    }

                                }
                            }                       
                        }    
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }           
            }

0 个答案:

没有答案