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


Java Geocoder.getFromLocationName方法代码示例

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


在下文中一共展示了Geocoder.getFromLocationName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getLocationFromAddress

import android.location.Geocoder; //导入方法依赖的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: call

import android.location.Geocoder; //导入方法依赖的package包/类
@Override
public void call(Subscriber<? super List<Address>> subscriber) {
    Geocoder geocoder = new Geocoder(ctx);
    List<Address> result;

    try {
        if (bounds != null) {
            result = geocoder.getFromLocationName(locationName, maxResults, bounds.southwest.latitude, bounds.southwest.longitude, bounds.northeast.latitude, bounds.northeast.longitude);
        } else {
            result = geocoder.getFromLocationName(locationName, maxResults);
        }

        if (!subscriber.isUnsubscribed()) {
            subscriber.onNext(result);
            subscriber.onCompleted();
        }
    } catch (IOException e) {
        if (!subscriber.isUnsubscribed()) {
            subscriber.onError(e);
        }
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:GeocodeObservable.java

示例3: getLatLng

import android.location.Geocoder; //导入方法依赖的package包/类
public static Address getLatLng(String location, Context mContext) {
        Address address = null;
        try {
            Geocoder gc = new Geocoder(mContext);
            List<Address> addresses = gc.getFromLocationName(location, 1); // get the found Address Objects

            for (Address a : addresses) {
                if (a.hasLatitude() && a.hasLongitude()) {
//                    Log.i(TAG, String.valueOf(location + "   " + a.getLatitude() + "
// " + a.getLongitude()));
                    address = a;
                } else {
                    Log.d(TAG, " this location has no entry " + location);
                }
            }
        } catch (IOException e) {
            // handle the exception
        }

        return address;
    }
 
开发者ID:shashkiranr,项目名称:RxRetrofit-Android,代码行数:22,代码来源:DateTimeUtils.java

示例4: GetLoc

import android.location.Geocoder; //导入方法依赖的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

示例5: doInBackground

import android.location.Geocoder; //导入方法依赖的package包/类
@Override
protected Address doInBackground(String... params) {
   	final Geocoder geocoder = new Geocoder(activity);
  		List<Address> addressList;
	try {
		addressList = geocoder.getFromLocationName(params[0], 1);
   		if (addressList != null && addressList.size() > 0) {
   			return addressList.get(0);
   		}
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
  		return null;
}
 
开发者ID:rtr-nettest,项目名称:open-rmbt,代码行数:17,代码来源:MapLocationRequestTask.java

示例6: onMapSearch

import android.location.Geocoder; //导入方法依赖的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

示例7: onQueryTextSubmit

import android.location.Geocoder; //导入方法依赖的package包/类
@Override
public boolean onQueryTextSubmit(String query) {
    if(query.length() == 0)
        return false;
    // get location from api
    Geocoder geocoder = new Geocoder(this);
    List<Address> addresses;
    try {
        addresses = geocoder.getFromLocationName(query, 1);
    } catch (IOException e) {
        return true;
    }
    if(addresses.size() > 0) {
        searchPosition = new LatLng(addresses.get(0).getLatitude(), addresses.get(0).getLongitude());
    } else {
        // no result was found
        Toast.makeText(this, getString(R.string.no_result), Toast.LENGTH_SHORT).show();
        searchPosition = null;
        return true;
    }
    searchView.clearFocus();
    searchHistory.add(query);
    updateNowLocation(searchPosition, getString(R.string.choose_location_tag), true);
    return true;
}
 
开发者ID:w86763777,项目名称:BikeLine,代码行数:26,代码来源:ChooseLocationActivity.java

示例8: onSearch

import android.location.Geocoder; //导入方法依赖的package包/类
public void onSearch(View view) {
    EditText location_tf = (EditText) findViewById(R.id.TFaddress);
    String location = location_tf.getText().toString();
    List <android.location.Address> addressList = null;
    if (location != null || !location.equals(' ')) {
        Geocoder geocoder = new Geocoder(this);
        try {
            addressList = geocoder.getFromLocationName(location, 1);
        } catch (IOException e) {
            e.printStackTrace();
        }

        android.location.Address address = addressList.get(0);
        LatLng latlng = new LatLng(address.getLatitude() , address.getLongitude());
        mMap.addMarker(new MarkerOptions().position(latlng).title("Marker"));
        mMap.animateCamera(CameraUpdateFactory.newLatLng(latlng));
    }
}
 
开发者ID:GitWebX,项目名称:hubISM,代码行数:19,代码来源:Campus_Map.java

示例9: doInBackground

import android.location.Geocoder; //导入方法依赖的package包/类
@Override
protected LatLng doInBackground(Void... params) {
    Geocoder gc = new Geocoder(Application.getContext());
    LatLng latLng = null;
    try {
        List<Address> address = gc.getFromLocationName(location, 1);

        for (Address a : address) {
            if (a.hasLatitude() && a.hasLongitude()) {
                Double lat = a.getLatitude();
                Double longitude = a.getLongitude();

                latLng = new LatLng(lat, longitude);
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    return latLng;
}
 
开发者ID:STUDIO-apps,项目名称:GeoShare_Android,代码行数:22,代码来源:GeocodingFromAddressTask.java

示例10: findLocationWithAddress

import android.location.Geocoder; //导入方法依赖的package包/类
private Location findLocationWithAddress() {
    double longitude = 0, latitude = 0;
    Customer customer = getActivity().getIntent().getParcelableExtra("USER_OBJECT");

    try {
        Geocoder geocoder = new Geocoder(getActivity(), Locale.getDefault());
        List<Address> addresses = geocoder.getFromLocationName(customer.getAddress(), 1);

        if(addresses != null && addresses.size() > 0) {
            longitude = addresses.get(0).getLongitude();
            latitude = addresses.get(0).getLatitude();

            Location addressLocation = new Location("");
            addressLocation.setLatitude(latitude);
            addressLocation.setLongitude(longitude);

            return addressLocation;
        }

        return null;
    }
    catch (IOException ex) {
        return null;
    }
}
 
开发者ID:chooonho,项目名称:GrabbyGas,代码行数:26,代码来源:SelectSupplierFragment.java

示例11: getLocationFromAddress

import android.location.Geocoder; //导入方法依赖的package包/类
public LatLng getLocationFromAddress(String strAddress) {
    Geocoder coder = new Geocoder(this);
    List<Address> address;
    LatLng p1 = null;

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

        p1 = new LatLng(location.getLatitude(), location.getLongitude() );

    } catch (Exception ex) {

        ex.printStackTrace();
        return null;
    }

    return p1;
}
 
开发者ID:letolab,项目名称:LETO-Toggl_Android,代码行数:25,代码来源:GeofenceSettingsActivity.java

示例12: getAddressFromLocationName

import android.location.Geocoder; //导入方法依赖的package包/类
public static Address getAddressFromLocationName(Context context, String locationName) {
    int maxResults = 1;
    Address address = null;
    List<Address> addresses = null;

    Geocoder gcd = getGeocoder(context);

    if (gcd == null) {
        return null;
    }

    try {
        addresses = gcd.getFromLocationName(locationName, maxResults);
    } catch (IOException e) {
        AppLog.e(AppLog.T.UTILS, "Failed to get coordinates from location", e);
    }

    // addresses may be null or empty if network isn't connected
    if (addresses != null && addresses.size() > 0) {
        address = addresses.get(0);
    }

    return address;
}
 
开发者ID:ldsddn,项目名称:wordpress_app_android,代码行数:25,代码来源:GeocoderUtils.java

示例13: getCoordinates

import android.location.Geocoder; //导入方法依赖的package包/类
public Address getCoordinates() {
    Geocoder geocoder = new Geocoder(getActivity(), Locale.getDefault());
    int nbTry = 0;
    List<Address> addressList = new ArrayList<>();
    try {
        addressList = geocoder.getFromLocationName(addressEditText.getText().toString(),1);
        while (addressList.size()==0 && nbTry<10) {
            Log.i(TAG, "Try number : "+nbTry);
            addressList = geocoder.getFromLocationName(addressEditText.getText().toString(), 1);
            nbTry++;
        }
        if (addressList.size()>0) {
            return addressList.get(0);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:IsticGLA,项目名称:SIT,代码行数:20,代码来源:InterventionDialogFragment.java

示例14: findCoordinates

import android.location.Geocoder; //导入方法依赖的package包/类
/**
 * Find Coordinates for a given address
 *
 * @param address address as text
 * @return coordinate near the given address
 * @throws AddressNotFoundException
 */
public LatLng findCoordinates(String address) throws CoordinatesNotFoundException {
    /* get latitude and longitude from the address */
    Geocoder geoCoder = new Geocoder(context, Locale.getDefault());
    try {
        List<Address> addresses = geoCoder.getFromLocationName(address, 5);
        if (addresses.size() > 0) {
            Double lat = (addresses.get(0).getLatitude());
            Double lon = (addresses.get(0).getLongitude());

            Log.d("lat-lon", lat + "......." + lon);
            final LatLng location = new LatLng(lat, lon);
            return location;
        } else {
            throw new CoordinatesNotFoundException(address);
        }
    } catch (IOException e) {
        Log.e(e);
    }

    return null;
}
 
开发者ID:Power-Switch,项目名称:PowerSwitch_Android,代码行数:29,代码来源:MapViewHandler.java

示例15: doInBackground

import android.location.Geocoder; //导入方法依赖的package包/类
protected List<Address> doInBackground(String... s) {
			lastGeocodedAddr[fromOrTo] = s[0];
			Geocoder geoCoder = new Geocoder(getBaseContext(), Locale.getDefault());
			try {
				Log.d("AddressGeoCoder", "Addr: " + s[0]);
				//List<Address> addresses = geoCoder.getFromLocationName(s[0], 5, -35.321848, -59.295959, -34.04697, -57.77298);
				List<Address> addresses = geoCoder.getFromLocationName(s[0], 5);
				return addresses;
			} catch (IOException e) {
//				e.printStackTrace();
				Log.e("ADdressToPointGeocodertask", "Geocoder failed", e);
				return null;
				/*Address temp1 = new Address(Locale.getDefault());
				temp1.setAddressLine(0, "test1 " + new Random().nextLong());
				Address temp2 = new Address(Locale.getDefault());
				temp2.setAddressLine(0, "test2 " + new Random().nextLong());
				List<Address> list = new ArrayList<Address>(2);
				list.add(temp1);
				list.add(temp2);
				return list;*/
			}
		}
 
开发者ID:Hellek1,项目名称:viaja-facil,代码行数:23,代码来源:ViajaFacilActivity.java


注:本文中的android.location.Geocoder.getFromLocationName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。