GMapsFX Elevation Example
GMapsFX its a javafx API that is wrapped around Google Maps javascript API.Its helpful for us who are not well versed in javascript.This is made possible in javafx cause of the WebEngine class read the documentation.
In this post am going to show you how to get the Elevation of a path.
First download the jar file and add it to your classpath.
There is a simple example here .Since i just want to show you the use of the PathElevationRequest class .You can just add this code to the example.
Dont know how to setup a BarChart check last post.
//the path
LatLong[] path={new LatLong(-1.2920659,36.821946),new LatLong(25.2048493,55.2707828),new LatLong(27.9879017,86.92531409999992), new LatLong(-25.274398,133.77513599999997)};
//takes an array of path and int for how many samples to return
PathElevationRequest path_elev_req=new PathElevationRequest(path,256);
//a request to the Google maps elevation service
ElevationService elev_service=new ElevationService();
//add XYChart.Series to this list,in this case 256 series
ObservableList<XYChart.Series> list=FXCollections.observableArrayList();
//we want the elevation of a given path,we call this method
elev_service.getElevationAlongPath(path_elev_req,new ElevationServiceCallback(){
@Override
public void elevationsReceived(ElevationResult[] ers, ElevationStatus es) {
if(ElevationStatus.OK==ElevationStatus.OK){
for (ElevationResult er : ers) {
//er.getElevation() returns a double
XYChart.Series series=new XYChart.Series();
series.getData().add(new XYChart.Data<>("",er.getElevation()));
list.add(series);
}
chart.getData().addAll(list);
}else{
System.out.println(es.getName());
}
}
}
});
To draw the polyline
PolylineOptions line_opt;
Polyline line;
line_opt=new PolylineOptions();
line_opt.path(new MVCArray(path))
.clickable(false)
.draggable(false)
.editable(false)
.strokeColor("#ff4500")
.strokeWeight(2)
.visible(true);
line=new Polyline(line_opt);
//add the Ployline which extends Mapshape to map
map.addMapShape(line);
Results
In this post am going to show you how to get the Elevation of a path.
First download the jar file and add it to your classpath.
There is a simple example here .Since i just want to show you the use of the PathElevationRequest class .You can just add this code to the example.
Dont know how to setup a BarChart check last post.
//the path
LatLong[] path={new LatLong(-1.2920659,36.821946),new LatLong(25.2048493,55.2707828),new LatLong(27.9879017,86.92531409999992), new LatLong(-25.274398,133.77513599999997)};
//takes an array of path and int for how many samples to return
PathElevationRequest path_elev_req=new PathElevationRequest(path,256);
//a request to the Google maps elevation service
ElevationService elev_service=new ElevationService();
//add XYChart.Series to this list,in this case 256 series
ObservableList<XYChart.Series> list=FXCollections.observableArrayList();
//we want the elevation of a given path,we call this method
elev_service.getElevationAlongPath(path_elev_req,new ElevationServiceCallback(){
@Override
public void elevationsReceived(ElevationResult[] ers, ElevationStatus es) {
if(ElevationStatus.OK==ElevationStatus.OK){
for (ElevationResult er : ers) {
//er.getElevation() returns a double
XYChart.Series series=new XYChart.Series();
series.getData().add(new XYChart.Data<>("",er.getElevation()));
list.add(series);
}
chart.getData().addAll(list);
}else{
System.out.println(es.getName());
}
}
}
});
To draw the polyline
PolylineOptions line_opt;
Polyline line;
line_opt=new PolylineOptions();
line_opt.path(new MVCArray(path))
.clickable(false)
.draggable(false)
.editable(false)
.strokeColor("#ff4500")
.strokeWeight(2)
.visible(true);
line=new Polyline(line_opt);
//add the Ployline which extends Mapshape to map
map.addMapShape(line);
Results
From Nairobi to Nyahuru via Thika and Nyeri |
Nairobi to Australia via Dubai,Everest |
Comments
Post a Comment