當前位置: 首頁>>代碼示例>>Java>>正文


Java Address.getLatitude方法代碼示例

本文整理匯總了Java中android.location.Address.getLatitude方法的典型用法代碼示例。如果您正苦於以下問題:Java Address.getLatitude方法的具體用法?Java Address.getLatitude怎麽用?Java Address.getLatitude使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.location.Address的用法示例。


在下文中一共展示了Address.getLatitude方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getLocationFromAddress

import android.location.Address; //導入方法依賴的package包/類
/**
 * to get latitude and longitude of an address
 *
 * @param strAddress address string
 * @return lat and lng in comma separated string
 */
public String getLocationFromAddress(String strAddress) {

    Geocoder coder = new Geocoder(mContext);
    List<Address> address;

    try {
        address = coder.getFromLocationName(strAddress, 1);
        if (address == null) {
            return null;
        }
        Address location = address.get(0);
        double lat = location.getLatitude();
        double lng = location.getLongitude();

        return lat + "," + lng;
    } catch (Exception e) {
        return null;
    }
}
 
開發者ID:SoftprodigyIndia,項目名稱:AndroidAppBoilerplate,代碼行數:26,代碼來源:LocationHelper.java

示例2: onCreate

import android.location.Address; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    String addressFormat = null;
    Address address = DateTimeUtils.getLatLng("seol", this);
    if (address != null) {
        addressFormat = address.getLatitude() + "," + address.getLongitude();
    } else {
        Log.d(TAG, "onCreate:  address not available");
    }


    Map<String, Object> data = new HashMap<>();
    data.put("location", addressFormat);
    data.put("timestamp", DateTimeUtils.getCurrentTimeinSeconds());
    data.put("key", API_KEY);

    RxRetrofit rxRetrofit = new RxRetrofit(this);
    rxRetrofit.getSimpleJsonQuery(BASE_URL,END_POINT_STRING, data, null,ApiDetail.class);
}
 
開發者ID:shashkiranr,項目名稱:RxRetrofit-Android,代碼行數:23,代碼來源:MainActivity.java

示例3: GetLoc

import android.location.Address; //導入方法依賴的package包/類
public void GetLoc(final String firstname, final String lastname, final String em, final String pass, String loc,String phone, final SharedPreferences sharedPref)
{

    Geocoder coder = new Geocoder(Authentication.this);
    List<Address> addresses;
    try {
        addresses = coder.getFromLocationName(loc, 5);
        if (addresses == null) {
        }
        Address location = addresses.get(0);
        double lat = location.getLatitude();
        double lng = location.getLongitude();
        Log.i("Lat",""+lat);
        Log.i("Lng",""+lng);
        //SetData(firstname,lastname,em,pass,loc,lat,lng,phone,sharedPref);

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


}
 
開發者ID:prabhavgupta,項目名稱:BookED,代碼行數:23,代碼來源:Authentication.java

示例4: onMapSearch

import android.location.Address; //導入方法依賴的package包/類
/**
     * Manipulates the map once available.
     * This callback is triggered when the map is ready to be used.
     * This is where we can add markers or lines, add listeners or move the camera. In this case,
     * we just add a marker near Sydney, Australia.
     * If Google Play services is not installed on the device, the user will be prompted to install
     * it inside the SupportMapFragment. This method will only be triggered once the user has
     * installed Google Play services and returned to the app.
     */

public void onMapSearch(View view) {
    EditText addressBar = (EditText) findViewById(R.id.txtAddress);
    String strAddress = addressBar.getText().toString();
    List<Address> address = new ArrayList();


        Geocoder coder = new Geocoder(getApplicationContext(), Locale.getDefault());
        try {

            address = coder.getFromLocationName(strAddress, 5);

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    if (address != null) {
        Address location = address.get(0);
        LatLng destination = new LatLng(location.getLatitude(), location.getLongitude());

        mMap.addMarker(new MarkerOptions().position(destination).title("Marker in Destination"));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(destination));
    }
}
 
開發者ID:JayWilliamsJr,項目名稱:Find-It-Location-Finder,代碼行數:33,代碼來源:MapsActivity.java

示例5: doInBackground

import android.location.Address; //導入方法依賴的package包/類
protected String doInBackground(String... args) {

            try {
                Geocoder coder = new Geocoder(context);
                List<Address> listadd;
                listadd = coder.getFromLocationName(addresstxt, 5);
                if (listadd == null) {
                }
                Address location = listadd.get(0);
                FLat = location.getLatitude();
                FLon = location.getLongitude();
                SavLat = FLat;
                SavLon = FLon;

                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        tempm.setPosition(new LatLng(FLat, FLon));
                        tempm.setTitle(addresstxt + "\n");
                        tempm.setSnippet("Click to set as work ");
                        tempm.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
                        tempm.setVisible(true);
                        mAddGeofencesButton.setVisibility(View.VISIBLE);
                        CameraPosition camPos = new CameraPosition.Builder()
                                .target(new LatLng(FLat, FLon))
                                .zoom(12.8f)
                                .build();

                        CameraUpdate camUpdate = CameraUpdateFactory.newCameraPosition(camPos);
                        map.moveCamera(camUpdate);
                    }
                });
            }
            catch(Exception e)
            {
            }
            return null;
        }
 
開發者ID:SkylineLabs,項目名稱:FindX,代碼行數:39,代碼來源:SelectWork.java

示例6: doInBackground

import android.location.Address; //導入方法依賴的package包/類
protected String doInBackground(String... args) {

            try {
                Geocoder coder = new Geocoder(context);
                List<Address> listadd;
                listadd = coder.getFromLocationName(addresstxt, 5);
                if (listadd == null) {
                  }
                Address location = listadd.get(0);
                FLat = location.getLatitude();
                FLon = location.getLongitude();
                SavLat = FLat;
                SavLon = FLon;

                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                            tempm.setPosition(new LatLng(FLat, FLon));
                            tempm.setTitle(addresstxt + "\n");
                            tempm.setSnippet("Click to set as location");
                            tempm.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
                            tempm.setVisible(true);
                            mAddGeofencesButton.setVisibility(View.VISIBLE);
                            CameraPosition camPos = new CameraPosition.Builder()
                                .target(new LatLng(FLat, FLon))
                                .zoom(12.8f)
                                .build();

                            CameraUpdate camUpdate = CameraUpdateFactory.newCameraPosition(camPos);
                            map.moveCamera(camUpdate);
                    }
                });
            }
            catch(Exception e)
            {
            }
            return null;
        }
 
開發者ID:SkylineLabs,項目名稱:FindX,代碼行數:39,代碼來源:SelectHome.java

示例7: onHandleIntent

import android.location.Address; //導入方法依賴的package包/類
@Override
protected void onHandleIntent(Intent intent) {
    String errorMessage = "";

    ResultReceiver receiver = intent.getParcelableExtra(RECEIVER);

    // Get the location passed to this service through an extra.
    String addressToGeocode = intent.getStringExtra(ADDRESS_DATA_EXTRA);

    List<Address> addresses = null;
    Geocoder geocoder = new Geocoder(this, Locale.getDefault());

    try {
        addresses = geocoder.getFromLocationName(addressToGeocode,
                // In this sample, get just a single address.
                 1);
    } catch (IOException ioException) {
        // Catch network or other I/O problems.
        errorMessage = getString(R.string.service_not_available);
        Log.e(TAG, errorMessage, ioException);
    } catch (IllegalArgumentException illegalArgumentException) {
        // Catch invalid latitude or longitude values.
        errorMessage = getString(R.string.invalid_lat_lng_used);
        Log.e(TAG, errorMessage, illegalArgumentException);
    }

    // Handle case where no address was found.
    if (addresses == null || addresses.size()  == 0) {
        if (errorMessage.isEmpty()) {
            errorMessage = getString(R.string.no_address_found);
            Log.e(TAG, errorMessage);
        }
        deliverResultToReceiver(FAILURE_RESULT, new LatLng(0.0, 0.0), receiver);
    } else {
        Address address = addresses.get(0);

        if (address.getLatitude() != 0.0 || address.getLongitude() != 0.0) {
            deliverResultToReceiver(SUCCESS_RESULT, new LatLng(address.getLatitude(), address.getLongitude()), receiver);
        } else {
            deliverResultToReceiver(FAILURE_RESULT, new LatLng(0.0, 0.0), receiver);
        }
    }
}
 
開發者ID:hypertrack,項目名稱:hypertrack-live-android,代碼行數:44,代碼來源:FetchLocationIntentService.java

示例8: doInBackground

import android.location.Address; //導入方法依賴的package包/類
protected String doInBackground(String... args) {


                    try {

                        Geocoder coder = new Geocoder(context);
                        List<Address> listadd;

                        listadd = coder.getFromLocationName(addresstxt, 5);

                        if (listadd == null) {
                            //Toast.makeText(getApplicationContext(), "Location not found, try again error step 1",
                            // .LENGTH_LONG).show();

                        }

                        Address location = listadd.get(0);
                        FLat = location.getLatitude();
                        FLon = location.getLongitude();


                        runOnUiThread(new Runnable() {
                            //
                            @Override
                            public void run() {


                                // Toast.makeText(getApplicationContext(), "  " + FLat + "   " + FLon, Toast.LENGTH_LONG).show();

                    if (home) {
                        tempm.setPosition(new LatLng(FLat, FLon));
                        tempm.setTitle(addresstxt + "\n");
                        tempm.setSnippet("Home");
                        tempm.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
                        tempm.setVisible(true);
                        mAddGeofencesButton.setVisibility(View.VISIBLE);
                    }

                    if (work) {
                        tempm.setPosition(new LatLng(FLat, FLon));
                        tempm.setTitle(addresstxt + "\n");
                        tempm.setSnippet("Work");
                        tempm.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
                        tempm.setVisible(true);
                        mAddGeofencesButton.setVisibility(View.VISIBLE);
                    }

                    if (other) {
                        tempm.setPosition(new LatLng(FLat, FLon));
                        tempm.setTitle(addresstxt + "\n");
                        tempm.setSnippet("Other");
                        tempm.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
                        tempm.setVisible(true);
                        mAddGeofencesButton.setVisibility(View.VISIBLE);
                    }

                    CameraPosition camPos = new CameraPosition.Builder()

                            .target(new LatLng(FLat, FLon))

                            .zoom(12.8f)

                            .build();

                    CameraUpdate camUpdate = CameraUpdateFactory.newCameraPosition(camPos);

                    map.moveCamera(camUpdate);

                            }
                        });


                }

                catch(Exception e)
                {
                }

            return null;
        }
 
開發者ID:SkylineLabs,項目名稱:FindX,代碼行數:81,代碼來源:Location_event.java


注:本文中的android.location.Address.getLatitude方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。