com.google.maps.GeocodingApi Java Examples
The following examples show how to use
com.google.maps.GeocodingApi.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LatLongFromLocation.java From PokeMate with GNU General Public License v3.0 | 6 votes |
public boolean parseLocation(String locationName){ String ERROR_MESSAGE = "Couldn't find specified custom location, falling back to co-ordinates"; if (locationName == null || locationName.equals("")) { System.out.println(ERROR_MESSAGE); return false; } GeoApiContext context = new GeoApiContext().setApiKey(GoogleApiKey); try { GeocodingResult[] request = GeocodingApi.newRequest(context).address(locationName).await(); LatLng location = request[0].geometry.location; latitude = location.lat; longitude = location.lng; System.out.println("Found custom location to be: " + request[0].formattedAddress); return true; } catch (Exception e) { System.out.println(ERROR_MESSAGE); return false; } }
Example #2
Source File: MentorUtils.java From lemonaid with MIT License | 5 votes |
public Point getLocationOfMentor(Mentor mentor) { GeoApiContext context = new GeoApiContext().setApiKey("AIzaSyC9hT7x8gTBdXcTSEy6XU_EWpr_WDe8lSY"); try { String address = ""; if (mentor.getAddress1() != null && mentor.getAddress1().length() > 0 ) { address += (address.length() > 0 ? ", " : "") + mentor.getAddress1(); } if (mentor.getAddress2() != null && mentor.getAddress2().length() > 0 ) { address += (address.length() > 0 ? ", " : "") + mentor.getAddress2(); } if (mentor.getZip() != null && mentor.getZip().length() > 0 ) { address += (address.length() > 0 ? ", " : "") + mentor.getZip(); } if (mentor.getCity() != null && mentor.getCity().length() > 0 ) { address += (address.length() > 0 ? ", " : "") + mentor.getCity(); } if (mentor.getState() != null && mentor.getState().length() > 0 ) { address += (address.length() > 0 ? ", " : "") + mentor.getState(); } if (mentor.getCountryId() != null && mentor.getCountryId().getName() != null && mentor.getCountryId().getName().length() > 0 ) { address += (address.length() > 0 ? ", " : "") + mentor.getCountryId().getName(); } if (address.length() > 0) { GeocodingResult[] results = GeocodingApi.geocode(context, address).await(); return new Point(results[0].geometry.location.lat, results[0].geometry.location.lng); } else { log.error("Unable to geocode address of " + mentor.getFullName() + ": No address available"); return null; } } catch (Exception e) { log.error("Unable to geocode address of " + mentor.getFullName() + ": " + e.toString()); return null; } }
Example #3
Source File: MentorUtils.java From lemonaid with MIT License | 5 votes |
public Point getPublicLocationOfMentor(Mentor mentor) { GeoApiContext context = new GeoApiContext().setApiKey("AIzaSyC9hT7x8gTBdXcTSEy6XU_EWpr_WDe8lSY"); try { String address = ""; if (mentor.getAddress1() != null && mentor.getAddress1().length() > 0 && mentor.getAddress1Public()) { address += (address.length() > 0 ? ", " : "") + mentor.getAddress1(); } if (mentor.getAddress2() != null && mentor.getAddress2().length() > 0 && mentor.getAddress2Public()) { address += (address.length() > 0 ? ", " : "") + mentor.getAddress2(); } if (mentor.getZip() != null && mentor.getZip().length() > 0 && mentor.getZipPublic()) { address += (address.length() > 0 ? ", " : "") + mentor.getZip(); } if (mentor.getCity() != null && mentor.getCity().length() > 0 && mentor.getCityPublic()) { address += (address.length() > 0 ? ", " : "") + mentor.getCity(); } if (mentor.getState() != null && mentor.getState().length() > 0 && mentor.getStatePublic()) { address += (address.length() > 0 ? ", " : "") + mentor.getState(); } if (mentor.getCountryId() != null && mentor.getCountryId().getName() != null && mentor.getCountryId().getName().length() > 0 && mentor.getCountryPublic()) { address += (address.length() > 0 ? ", " : "") + mentor.getCountryId().getName(); } if (address.length() > 0) { GeocodingResult[] results = GeocodingApi.geocode(context, address).await(); return new Point(results[0].geometry.location.lat, results[0].geometry.location.lng); } else { log.error("Unable to geocode address of " + mentor.getFullName() + ": No address available"); return null; } } catch (Exception e) { log.error("Unable to geocode address of " + mentor.getFullName() + ": " + e.toString()); return null; } }
Example #4
Source File: MainActivity.java From roads-api-samples with Apache License 2.0 | 5 votes |
/** * Geocodes a Snapped Point using the Place ID. */ private GeocodingResult geocodeSnappedPoint(GeoApiContext context, SnappedPoint point) throws Exception { GeocodingResult[] results = GeocodingApi.newRequest(context) .place(point.placeId) .await(); if (results.length > 0) { return results[0]; } return null; }