本文整理汇总了Java中com.google.maps.GeoApiContext类的典型用法代码示例。如果您正苦于以下问题:Java GeoApiContext类的具体用法?Java GeoApiContext怎么用?Java GeoApiContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GeoApiContext类属于com.google.maps包,在下文中一共展示了GeoApiContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:Celethor,项目名称:CS360proj1,代码行数:20,代码来源:EarthSearch.java
示例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();
}
开发者ID:Celethor,项目名称:CS360proj1,代码行数:20,代码来源:EarthSearch.java
示例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;
}
开发者ID:Celethor,项目名称:CS360proj1,代码行数:16,代码来源:EarthSearch.java
示例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;
}
开发者ID:Celethor,项目名称:CS360proj1,代码行数:16,代码来源:EarthSearch.java
示例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;
}
}
开发者ID:teamOtee,项目名称:x-facteur,代码行数:21,代码来源:DistanceMatrixHTTPGetter.java
示例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()));
}
开发者ID:nogalavi,项目名称:Bikeable,代码行数:19,代码来源:SearchHistoryCollector.java
示例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;
}
开发者ID:2DV603NordVisaProject,项目名称:nordvisa_calendar,代码行数:62,代码来源:GeoCodeHandler.java
示例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;
}
}
开发者ID:SofiaRosetti,项目名称:S3-16-d-rescue,代码行数:22,代码来源:GeocodingImpl.java
示例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;
}
}
开发者ID:sapmentors,项目名称:lemonaid,代码行数:36,代码来源:MentorUtils.java
示例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;
}
}
开发者ID:sapmentors,项目名称:lemonaid,代码行数:36,代码来源:MentorUtils.java
示例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());
}
});
}
开发者ID:agenthun,项目名称:ESeal,代码行数:44,代码来源:NfcDeviceFragment.java
示例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;
}
开发者ID:andju,项目名称:findlunch,代码行数:34,代码来源:RestaurantController.java
示例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);
}
开发者ID:healthbam,项目名称:healthbam,代码行数:15,代码来源:DefaultGoogleGeocodeClient.java
示例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;
}
开发者ID:ghillert,项目名称:gps-vehicle-simulator,代码行数:30,代码来源:DefaultPathService.java
示例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;
}
开发者ID:nogalavi,项目名称:Bikeable,代码行数:10,代码来源:DirectionsManager.java
示例16: getElevationSamples
import com.google.maps.GeoApiContext; //导入依赖的package包/类
public ElevationResult[] getElevationSamples(int numOfSamples) {
ElevationResult[] elevations = null;
GeoApiContext context = new GeoApiContext().setApiKey("AIzaSyBq4x4t8-j30Vbo5jrax_jIMkkMTlZdp1k");
try {
elevations = ElevationApi.getByPath(context, numOfSamples, route).await();
} catch (Exception e) {
System.out.println("Failed getting elevation info");
e.printStackTrace();
}
return elevations;
}
开发者ID:nogalavi,项目名称:Bikeable,代码行数:14,代码来源:PathElevationQuerier.java
示例17: onCreate
import com.google.maps.GeoApiContext; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
mProgressBar = (ProgressBar) findViewById(R.id.progress_bar);
SupportMapFragment mapFragment =
(SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
mContext = new GeoApiContext().setApiKey(getString(R.string.google_maps_web_services_key));
}
开发者ID:googlemaps,项目名称:roads-api-samples,代码行数:14,代码来源:MainActivity.java
示例18: snapToRoads
import com.google.maps.GeoApiContext; //导入依赖的package包/类
/**
* Snaps the points to their most likely position on roads using the Roads API.
*/
private List<SnappedPoint> snapToRoads(GeoApiContext context) throws Exception {
List<SnappedPoint> snappedPoints = new ArrayList<>();
int offset = 0;
while (offset < mCapturedLocations.size()) {
// Calculate which points to include in this request. We can't exceed the APIs
// maximum and we want to ensure some overlap so the API can infer a good location for
// the first few points in each request.
if (offset > 0) {
offset -= PAGINATION_OVERLAP; // Rewind to include some previous points
}
int lowerBound = offset;
int upperBound = Math.min(offset + PAGE_SIZE_LIMIT, mCapturedLocations.size());
// Grab the data we need for this page.
LatLng[] page = mCapturedLocations
.subList(lowerBound, upperBound)
.toArray(new LatLng[upperBound - lowerBound]);
// Perform the request. Because we have interpolate=true, we will get extra data points
// between our originally requested path. To ensure we can concatenate these points, we
// only start adding once we've hit the first new point (i.e. skip the overlap).
SnappedPoint[] points = RoadsApi.snapToRoads(context, true, page).await();
boolean passedOverlap = false;
for (SnappedPoint point : points) {
if (offset == 0 || point.originalIndex >= PAGINATION_OVERLAP) {
passedOverlap = true;
}
if (passedOverlap) {
snappedPoints.add(point);
}
}
offset = upperBound;
}
return snappedPoints;
}
开发者ID:googlemaps,项目名称:roads-api-samples,代码行数:42,代码来源:MainActivity.java
示例19: getSpeedLimits
import com.google.maps.GeoApiContext; //导入依赖的package包/类
/**
* Retrieves speed limits for the previously-snapped points. This method is efficient in terms
* of quota usage as it will only query for unique places.
*
* Note: Speed Limit data is only available with an enabled Maps for Work API key.
*/
private Map<String, SpeedLimit> getSpeedLimits(GeoApiContext context, List<SnappedPoint> points)
throws Exception {
Map<String, SpeedLimit> placeSpeeds = new HashMap<>();
// Pro tip: save on quota by filtering to unique place IDs
for (SnappedPoint point : points) {
placeSpeeds.put(point.placeId, null);
}
String[] uniquePlaceIds =
placeSpeeds.keySet().toArray(new String[placeSpeeds.keySet().size()]);
// Loop through the places, one page (API request) at a time.
for (int i = 0; i < uniquePlaceIds.length; i += PAGE_SIZE_LIMIT) {
String[] page = Arrays.copyOfRange(uniquePlaceIds, i,
Math.min(i + PAGE_SIZE_LIMIT, uniquePlaceIds.length));
// Execute!
SpeedLimit[] placeLimits = RoadsApi.speedLimits(context, page).await();
for (SpeedLimit sl : placeLimits) {
placeSpeeds.put(sl.placeId, sl);
}
}
return placeSpeeds;
}
开发者ID:googlemaps,项目名称:roads-api-samples,代码行数:33,代码来源:MainActivity.java
示例20: geocodeSnappedPoint
import com.google.maps.GeoApiContext; //导入依赖的package包/类
/**
* 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;
}
开发者ID:googlemaps,项目名称:roads-api-samples,代码行数:14,代码来源:MainActivity.java
注:本文中的com.google.maps.GeoApiContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论