当前位置: 首页>>代码示例>>Java>>正文


Java Address.getLongitude方法代码示例

本文整理汇总了Java中android.location.Address.getLongitude方法的典型用法代码示例。如果您正苦于以下问题:Java Address.getLongitude方法的具体用法?Java Address.getLongitude怎么用?Java Address.getLongitude使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.location.Address的用法示例。


在下文中一共展示了Address.getLongitude方法的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.getLongitude方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。