本文整理汇总了Java中com.google.maps.GeoApiContext类的典型用法代码示例。如果您正苦于以下问题:Java GeoApiContext类的具体用法?Java GeoApiContext怎么用?Java GeoApiContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GeoApiContext类属于com.google.maps包,在下文中一共展示了GeoApiContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDriveDist
import com.google.maps.GeoApiContext; //导入依赖的package包/类
public static long getDriveDist(String addrOne, String addrTwo) throws ApiException, InterruptedException, IOException{
//set up key
GeoApiContext distCalcer = new GeoApiContext.Builder()
.apiKey(API_KEY)
.build();
DistanceMatrixApiRequest req = DistanceMatrixApi.newRequest(distCalcer);
DistanceMatrix result = req.origins(addrOne)
.destinations(addrTwo)
.mode(TravelMode.DRIVING)
.avoid(RouteRestriction.TOLLS)
.language("en-US")
.await();
long distApart = result.rows[0].elements[0].distance.inMeters;
return distApart;
}
示例2: distanceMatrix
import com.google.maps.GeoApiContext; //导入依赖的package包/类
public static void distanceMatrix(String[] origins, String[] destinations) throws ApiException, InterruptedException, IOException{
GeoApiContext context = new GeoApiContext.Builder()
.apiKey(API_KEY)
.build();
DistanceMatrixApiRequest req=DistanceMatrixApi.newRequest(context);
DistanceMatrix t=req.origins(origins).destinations(destinations).mode(TravelMode.DRIVING).await();
//long[][] array=new long[origins.length][destinations.length];
File file=new File("Matrix.txt");
FileOutputStream out=new FileOutputStream(file);
DataOutputStream outFile=new DataOutputStream(out);
for(int i=0;i<origins.length;i++){
for(int j=0;j<destinations.length;j++){
//System.out.println(t.rows[i].elements[j].distance.inMeters);
outFile.writeLong(t.rows[i].elements[j].distance.inMeters);
}
}
outFile.close();
}
示例3: lookupAddr
import com.google.maps.GeoApiContext; //导入依赖的package包/类
public static String lookupAddr(String establishment) throws ApiException, InterruptedException, IOException {
//set up key
GeoApiContext lookupDoodad = new GeoApiContext.Builder()
.apiKey(API_KEY)
.build();
GeocodingResult[] results = GeocodingApi.geocode(lookupDoodad,
establishment).await();
//converts results into usable address
String address = (results[0].formattedAddress);
return address;
}
示例4: lookupCoord
import com.google.maps.GeoApiContext; //导入依赖的package包/类
public static LatLng lookupCoord(String establishment) throws ApiException, InterruptedException, IOException {
//set up key
GeoApiContext lookupDoodad = new GeoApiContext.Builder()
.apiKey(API_KEY)
.build();
GeocodingResult[] results = GeocodingApi.geocode(lookupDoodad,
establishment).await();
//converts results into usable Coordinates
LatLng coords = (results[0].geometry.location);
//System.out.println(results[0].geometry.location);
return coords;
}
示例5: getDistanceMatrix
import com.google.maps.GeoApiContext; //导入依赖的package包/类
public static DistanceMatrix getDistanceMatrix(boolean driving) {
String[] shipments = new String[1 + ShipmentController.getItems().size()];
shipments[0] = PathController.getWalkingPO().getAddress();
for (int i = 0; i < ShipmentController.getItems().size(); i++) {
shipments[i + 1] = ShipmentController.getItems().get(i).getAddress();
}
GeoApiContext context = new GeoApiContext().setApiKey(XFacteur.GOOGLE_API_KEY);
DistanceMatrixApiRequest req = DistanceMatrixApi.getDistanceMatrix(context, shipments, shipments);
req.language("fr-FR");
req.units(Unit.METRIC);
req.mode(driving ? TravelMode.DRIVING : TravelMode.WALKING);
try {
return req.await();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
示例6: SearchHistoryCollector
import com.google.maps.GeoApiContext; //导入依赖的package包/类
public SearchHistoryCollector(Context appContext, GeoApiContext geoApiContext) {
historyFileName = "Bikeable_History";
this.appContext = appContext;
this.geoApiContext = geoApiContext;
onlineHistory = new LinkedList<>();
historyFile = new File(appContext.getFilesDir(), historyFileName);
// create a new file if it doesn't exist
try {
historyFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
Log.i("INFO:", String.format("Before load history size %d", onlineHistory.size()));
loadSearchHistory();
Log.i("INFO:", String.format("After load history size %d", onlineHistory.size()));
}
示例7: getGeoCodedLocation
import com.google.maps.GeoApiContext; //导入依赖的package包/类
/**
* With the supplied address, this method uses the Google Maps API to retrieve geocoded
* information, such as coordinates, postalcode, city, country etc.
*
* @param address The address to geocode.
* @return An EventLocation object containing all geocoded data.
*/
static EventLocation getGeoCodedLocation(String address) {
EventLocation eventLocation = new EventLocation();
// Temporary API key
final String API_KEY = "AIzaSyAM9tW28Kcfem-zAIyyPnnPnyqL1WY5TGo";
GeoApiContext context = new GeoApiContext().setApiKey(API_KEY);
GeocodingApiRequest request = GeocodingApi.newRequest(context).address(address);
try {
GeocodingResult[] results = request.await();
List<Double> latlng = new ArrayList<>();
latlng.add(results[0].geometry.location.lng);
latlng.add(results[0].geometry.location.lat);
EventLocationCoordinates eventLocationCoordinates = new EventLocationCoordinates();
eventLocationCoordinates.setCoordinates(latlng);
eventLocation.setCoordinates(eventLocationCoordinates);
eventLocation.setAddress(address);
eventLocation.setParsedAddress(results[0].formattedAddress);
for (AddressComponent addressComponent : results[0].addressComponents) {
switch (addressComponent.types[0]) {
case POSTAL_CODE:
// Remove any white space from postal code
String postalCode = addressComponent.longName
.replaceAll("\\s+","");
eventLocation.setPostalCode(postalCode);
break;
case LOCALITY:
eventLocation.setCity(addressComponent.longName);
break;
case POSTAL_TOWN:
eventLocation.setCity(addressComponent.longName);
break;
case ADMINISTRATIVE_AREA_LEVEL_1:
eventLocation.setCounty(addressComponent.longName);
break;
case COUNTRY:
eventLocation.setCountry(addressComponent.shortName);
break;
default:
break;
}
}
} catch (Exception e) {
// Handle error
}
return eventLocation;
}
示例8: reverseGeocode
import com.google.maps.GeoApiContext; //导入依赖的package包/类
/**
* Sends a reverse geocode request obtaining the district identifier.
*
* @param latitude latitude value
* @param longitude longitude value
* @throws Exception if a geocoding error occurred
*/
private void reverseGeocode(final double latitude, final double longitude) throws Exception {
final GeoApiContext context = new GeoApiContext.Builder()
.apiKey(KEY)
.build();
final LatLng latlng = new LatLng(latitude, longitude);
final GeocodingResult[] results;
try {
results = GeocodingApi.reverseGeocode(context, latlng).await();
final Gson gson = new GsonBuilder().setPrettyPrinting().create();
this.response = gson.toJson(results[0].addressComponents);
} catch (final Exception e) {
throw e;
}
}
示例9: getLocationOfMentor
import com.google.maps.GeoApiContext; //导入依赖的package包/类
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;
}
}
示例10: getPublicLocationOfMentor
import com.google.maps.GeoApiContext; //导入依赖的package包/类
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;
}
}
示例11: processGoogleMapGeocodeLocation
import com.google.maps.GeoApiContext; //导入依赖的package包/类
private void processGoogleMapGeocodeLocation() {
GeoApiContext geoApiContext = new GeoApiContext().setApiKey(App.GOOGLE_MAP_API_KEY);
GeolocationPayload.GeolocationPayloadBuilder payloadBuilder = new GeolocationPayload.GeolocationPayloadBuilder()
.ConsiderIp(false);
Activity activity = getActivity();
CellTower.CellTowerBuilder cellTowerBuilder = new CellTower.CellTowerBuilder()
.CellId(NetUtil.getCellLocationCid(activity))
.LocationAreaCode(NetUtil.getCellLocationLac(activity))
.MobileCountryCode(Integer.parseInt(NetUtil.getTelephonyNetWorkOperatorMcc(activity)))
.MobileNetworkCode(Integer.parseInt(NetUtil.getTelephonyNetWorkOperatorMnc(activity)));
payloadBuilder.AddCellTower(cellTowerBuilder.createCellTower());
if (NetUtil.isWifi(getContext())) {
WifiAccessPoint.WifiAccessPointBuilder wifiAccessPointBuilder = new WifiAccessPoint.WifiAccessPointBuilder()
.MacAddress(NetUtil.getWifiMacAddress(activity))
.SignalStrength(NetUtil.getWifiRssi(activity));
payloadBuilder.AddWifiAccessPoint(wifiAccessPointBuilder.createWifiAccessPoint());
wifiAccessPointBuilder = new WifiAccessPoint.WifiAccessPointBuilder()
.MacAddress(NetUtil.getWifiInfo(activity).getBSSID());
payloadBuilder.AddWifiAccessPoint(wifiAccessPointBuilder.createWifiAccessPoint());
}
GeolocationApi.geolocate(geoApiContext, payloadBuilder.createGeolocationPayload())
.setCallback(new PendingResult.Callback<GeolocationResult>() {
@Override
public void onResult(GeolocationResult result) {
Log.d(TAG, "onResult() returned: " + result.location.toString());
}
@Override
public void onFailure(Throwable e) {
Log.d(TAG, "onFailure() returned: " + e.getMessage());
}
});
}
示例12: getLocationOfRestaurant
import com.google.maps.GeoApiContext; //导入依赖的package包/类
/**
* Gets the location of restaurant using the Google Geocoding API.
*
* @param restaurant
* Restaurant from which to get the location.
* @return the location of restaurant
*/
private String getLocationOfRestaurant(Restaurant restaurant, HttpServletRequest request) {
// Replace the API key below with a valid API key.
GeoApiContext context = new GeoApiContext().setApiKey("AIzaSyAvO9bl1Yi2hn7mkTSniv5lXaPRii1JxjI");
GeocodingApiRequest req = GeocodingApi.newRequest(context).address(String.format("%1$s %2$s, %3$s %4$s", restaurant.getStreetNumber(), restaurant.getStreet(), restaurant.getZip(), restaurant.getCity()));
try {
GeocodingResult[] result = req.await();
if (result != null && result.length > 0) {
// Handle successful request.
GeocodingResult firstMatch = result[0];
if (firstMatch.geometry != null && firstMatch.geometry.location != null) {
restaurant.setLocationLatitude((float) firstMatch.geometry.location.lat);
restaurant.setLocationLongitude((float) firstMatch.geometry.location.lng);
} else {
return messageSource.getMessage("restaurant.addressNotResolveable", null, Locale.getDefault());
}
} else {
return messageSource.getMessage("restaurant.addressNotFound", null, Locale.getDefault());
}
} catch (Exception e) {
LOGGER.error(LogUtils.getExceptionMessage(request, Thread.currentThread().getStackTrace()[1].getMethodName(), e));
return messageSource.getMessage("restaurant.googleApiError", new String[] { e.getMessage() }, Locale.getDefault());
}
return null;
}
示例13: DefaultGoogleGeocodeClient
import com.google.maps.GeoApiContext; //导入依赖的package包/类
/**
* An injectable constructor.
*
* @param configService the {@link ConfigService} for config
*/
@Autowired
public DefaultGoogleGeocodeClient(
@Nonnull ConfigService configService
) {
LOGGER.debug("constructed");
requireNonNull(configService, "configService cannot be null");
String googleMapsApiKey = configService.getPublicConfig().getGoogleGeocodeClientId();
this.context = new GeoApiContext().setApiKey(googleMapsApiKey);
}
示例14: getCoordinatesFromGoogle
import com.google.maps.GeoApiContext; //导入依赖的package包/类
@Override
public List<Point> getCoordinatesFromGoogle(DirectionInput directionInput) {
final GeoApiContext context = new GeoApiContext().setApiKey(environment.getRequiredProperty("gpsSimmulator.googleApiKey"));
final DirectionsApiRequest request = DirectionsApi.getDirections(
context,
directionInput.getFrom(),
directionInput.getTo());
List<LatLng> latlongList = null;
try {
DirectionsRoute[] routes = request.await();
for (DirectionsRoute route : routes) {
latlongList = route.overviewPolyline.decodePath();
}
}
catch (Exception e) {
throw new IllegalStateException(e);
}
final List<Point> points = new ArrayList<>(latlongList.size());
for (LatLng latLng : latlongList) {
points.add(new Point(latLng.lat, latLng.lng));
}
return points;
}
示例15: DirectionsManager
import com.google.maps.GeoApiContext; //导入依赖的package包/类
public DirectionsManager(GeoApiContext context, GoogleMap mMap){
this.context = context;
if (mMap != null)
this.mMap = mMap;
calculatedRoutes = null;
directionBounds = null;
predictionFrom = null;
predictionTo = null;
}