Google Maps API extract elevation value along routeExport KML from points plotted in javascript Google Maps...
How to prevent "they're falling in love" trope
What does the expression "A Mann!" means
Bullying boss launched a smear campaign and made me unemployable
Forgetting the musical notes while performing in concert
Why would the Red Woman birth a shadow if she worshipped the Lord of the Light?
If human space travel is limited by the G force vulnerability, is there a way to counter G forces?
GFCI outlets - can they be repaired? Are they really needed at the end of a circuit?
Reverse dictionary where values are lists
What reasons are there for a Capitalist to oppose a 100% inheritance tax?
In 'Revenger,' what does 'cove' come from?
Can compressed videos be decoded back to their uncompresed original format?
Why no variance term in Bayesian logistic regression?
What is a romance in Latin?
How seriously should I take size and weight limits of hand luggage?
What mechanic is there to disable a threat instead of killing it?
ssTTsSTtRrriinInnnnNNNIiinngg
How could indestructible materials be used in power generation?
What method can I use to design a dungeon difficult enough that the PCs can't make it through without killing them?
Detention in 1997
Would Slavery Reparations be considered Bills of Attainder and hence Illegal?
Alternative to sending password over mail?
How much of data wrangling is a data scientist's job?
Is there an expression that means doing something right before you will need it rather than doing it in case you might need it?
Is it possible to create a QR code using text?
Google Maps API extract elevation value along route
Export KML from points plotted in javascript Google Maps API?Unit of Google Maps API geometry servicesGoogle Maps API v3 base map visibilityRemoving Google maps base layer from Google Maps APIExtracting latitude/longitude from javascript and passing to html formGoogle Maps Elevation licenseOpenlayers v4.0.1 support Google Maps Javascript API?How to dynamically load Google Maps markers around center coordinates?How to position custom button controls on Google Maps API?Point locator on polygon for onclick of elevation profile graph
I am using the Directions and Elevation Service of Google Maps, in order to extract the coordinates and the elevation along a route between a start and end point. I could set my directions service successfully, I could also extract the elevation values. Everything works fine at the first request, but if I send a second request I got the error message:
"InvalidValueError: in property path: fewer than 2 LatLngs".
I also noticed, that if I reload my page in Firefox, the error disappears. But if I don't reload my webpage, the error remains.
Below you can see my code:
$(window).on('load', function() {
var directionsDisplay;
directionsService = new google.maps.DirectionsService();
var map;
});
$(window).on('load', function () {
initMap();
});
function initMap() {
directionsDisplay = new google.maps.DirectionsRenderer();
var mapOptions = {
zoom: 7,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: new google.maps.LatLng(48.7758459, 9.1829321),
mapTypeControl: false
}
map = new google.maps.Map(document.getElementById("map"), mapOptions);
directionsDisplay.setMap(map);
}
//take start and end from input field
function calcRoute() {
var start = document.getElementById("start").value;
var end = document.getElementById("end").value;
//send request to server
var request = {
origin: start,
destination: end,
travelMode: google.maps.TravelMode.DRIVING
};
path = [];
//get result from google maps server as response
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
pointsArray = response.routes[0].overview_path;
var i = 0;
var j = 0;
//get long lat of vertices along route
for (j = 0; j < pointsArray.length; j++) {
lat = pointsArray[j].lat();
lng = pointsArray[j].lng();
//save lat long in path array
path.push(new google.maps.LatLng(lat, lng));
//create marker
var marker = new google.maps.Marker({
position: new google.maps.LatLng(lat, lng),
map: map
});
}
}
});
//Create an ElevationService
var elevator = new google.maps.ElevationService;
displayPathElevation(path, elevator, map);
function displayPathElevation(path, elevator, map) {
new google.maps.Polyline({
path: path,
strokeColor: '#0000CC',
strokeOpacity: 0.4,
map: map
});
elevator.getElevationAlongPath({
'path': path,
'samples': 256
}, plotElevation);
}
function plotElevation(elevations, status) {
if (status === 'OK') {
for (var i=0; i < elevations.length; i++) {
console.log(elevations[i].location.lat() );
console.log(elevations[i].location.lng() );
console.log(elevations[i].elevation);
}
}
};
Here are my libs and buttons:
<div id="wrapper">
<label for="Start">Start</label><input id="start" type="textbox"></input><br/>
<label for="End">End</label><input id="end" type="textbox"></input><br/><br/>
<input id="submit" type="button" class="btn btn-dark" value="search" onclick="calcRoute();"><br/><br/>
<div id="chart"></div>
</div>
<div id="map"></div>
<script defer src="https://maps.googleapis.com/maps/api /js?key=MY_API_KEY=initMap"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
javascript google-maps web-mapping google-maps-api google-maps-api-3
bumped to the homepage by Community♦ 8 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
I am using the Directions and Elevation Service of Google Maps, in order to extract the coordinates and the elevation along a route between a start and end point. I could set my directions service successfully, I could also extract the elevation values. Everything works fine at the first request, but if I send a second request I got the error message:
"InvalidValueError: in property path: fewer than 2 LatLngs".
I also noticed, that if I reload my page in Firefox, the error disappears. But if I don't reload my webpage, the error remains.
Below you can see my code:
$(window).on('load', function() {
var directionsDisplay;
directionsService = new google.maps.DirectionsService();
var map;
});
$(window).on('load', function () {
initMap();
});
function initMap() {
directionsDisplay = new google.maps.DirectionsRenderer();
var mapOptions = {
zoom: 7,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: new google.maps.LatLng(48.7758459, 9.1829321),
mapTypeControl: false
}
map = new google.maps.Map(document.getElementById("map"), mapOptions);
directionsDisplay.setMap(map);
}
//take start and end from input field
function calcRoute() {
var start = document.getElementById("start").value;
var end = document.getElementById("end").value;
//send request to server
var request = {
origin: start,
destination: end,
travelMode: google.maps.TravelMode.DRIVING
};
path = [];
//get result from google maps server as response
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
pointsArray = response.routes[0].overview_path;
var i = 0;
var j = 0;
//get long lat of vertices along route
for (j = 0; j < pointsArray.length; j++) {
lat = pointsArray[j].lat();
lng = pointsArray[j].lng();
//save lat long in path array
path.push(new google.maps.LatLng(lat, lng));
//create marker
var marker = new google.maps.Marker({
position: new google.maps.LatLng(lat, lng),
map: map
});
}
}
});
//Create an ElevationService
var elevator = new google.maps.ElevationService;
displayPathElevation(path, elevator, map);
function displayPathElevation(path, elevator, map) {
new google.maps.Polyline({
path: path,
strokeColor: '#0000CC',
strokeOpacity: 0.4,
map: map
});
elevator.getElevationAlongPath({
'path': path,
'samples': 256
}, plotElevation);
}
function plotElevation(elevations, status) {
if (status === 'OK') {
for (var i=0; i < elevations.length; i++) {
console.log(elevations[i].location.lat() );
console.log(elevations[i].location.lng() );
console.log(elevations[i].elevation);
}
}
};
Here are my libs and buttons:
<div id="wrapper">
<label for="Start">Start</label><input id="start" type="textbox"></input><br/>
<label for="End">End</label><input id="end" type="textbox"></input><br/><br/>
<input id="submit" type="button" class="btn btn-dark" value="search" onclick="calcRoute();"><br/><br/>
<div id="chart"></div>
</div>
<div id="map"></div>
<script defer src="https://maps.googleapis.com/maps/api /js?key=MY_API_KEY=initMap"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
javascript google-maps web-mapping google-maps-api google-maps-api-3
bumped to the homepage by Community♦ 8 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
I am using the Directions and Elevation Service of Google Maps, in order to extract the coordinates and the elevation along a route between a start and end point. I could set my directions service successfully, I could also extract the elevation values. Everything works fine at the first request, but if I send a second request I got the error message:
"InvalidValueError: in property path: fewer than 2 LatLngs".
I also noticed, that if I reload my page in Firefox, the error disappears. But if I don't reload my webpage, the error remains.
Below you can see my code:
$(window).on('load', function() {
var directionsDisplay;
directionsService = new google.maps.DirectionsService();
var map;
});
$(window).on('load', function () {
initMap();
});
function initMap() {
directionsDisplay = new google.maps.DirectionsRenderer();
var mapOptions = {
zoom: 7,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: new google.maps.LatLng(48.7758459, 9.1829321),
mapTypeControl: false
}
map = new google.maps.Map(document.getElementById("map"), mapOptions);
directionsDisplay.setMap(map);
}
//take start and end from input field
function calcRoute() {
var start = document.getElementById("start").value;
var end = document.getElementById("end").value;
//send request to server
var request = {
origin: start,
destination: end,
travelMode: google.maps.TravelMode.DRIVING
};
path = [];
//get result from google maps server as response
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
pointsArray = response.routes[0].overview_path;
var i = 0;
var j = 0;
//get long lat of vertices along route
for (j = 0; j < pointsArray.length; j++) {
lat = pointsArray[j].lat();
lng = pointsArray[j].lng();
//save lat long in path array
path.push(new google.maps.LatLng(lat, lng));
//create marker
var marker = new google.maps.Marker({
position: new google.maps.LatLng(lat, lng),
map: map
});
}
}
});
//Create an ElevationService
var elevator = new google.maps.ElevationService;
displayPathElevation(path, elevator, map);
function displayPathElevation(path, elevator, map) {
new google.maps.Polyline({
path: path,
strokeColor: '#0000CC',
strokeOpacity: 0.4,
map: map
});
elevator.getElevationAlongPath({
'path': path,
'samples': 256
}, plotElevation);
}
function plotElevation(elevations, status) {
if (status === 'OK') {
for (var i=0; i < elevations.length; i++) {
console.log(elevations[i].location.lat() );
console.log(elevations[i].location.lng() );
console.log(elevations[i].elevation);
}
}
};
Here are my libs and buttons:
<div id="wrapper">
<label for="Start">Start</label><input id="start" type="textbox"></input><br/>
<label for="End">End</label><input id="end" type="textbox"></input><br/><br/>
<input id="submit" type="button" class="btn btn-dark" value="search" onclick="calcRoute();"><br/><br/>
<div id="chart"></div>
</div>
<div id="map"></div>
<script defer src="https://maps.googleapis.com/maps/api /js?key=MY_API_KEY=initMap"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
javascript google-maps web-mapping google-maps-api google-maps-api-3
I am using the Directions and Elevation Service of Google Maps, in order to extract the coordinates and the elevation along a route between a start and end point. I could set my directions service successfully, I could also extract the elevation values. Everything works fine at the first request, but if I send a second request I got the error message:
"InvalidValueError: in property path: fewer than 2 LatLngs".
I also noticed, that if I reload my page in Firefox, the error disappears. But if I don't reload my webpage, the error remains.
Below you can see my code:
$(window).on('load', function() {
var directionsDisplay;
directionsService = new google.maps.DirectionsService();
var map;
});
$(window).on('load', function () {
initMap();
});
function initMap() {
directionsDisplay = new google.maps.DirectionsRenderer();
var mapOptions = {
zoom: 7,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: new google.maps.LatLng(48.7758459, 9.1829321),
mapTypeControl: false
}
map = new google.maps.Map(document.getElementById("map"), mapOptions);
directionsDisplay.setMap(map);
}
//take start and end from input field
function calcRoute() {
var start = document.getElementById("start").value;
var end = document.getElementById("end").value;
//send request to server
var request = {
origin: start,
destination: end,
travelMode: google.maps.TravelMode.DRIVING
};
path = [];
//get result from google maps server as response
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
pointsArray = response.routes[0].overview_path;
var i = 0;
var j = 0;
//get long lat of vertices along route
for (j = 0; j < pointsArray.length; j++) {
lat = pointsArray[j].lat();
lng = pointsArray[j].lng();
//save lat long in path array
path.push(new google.maps.LatLng(lat, lng));
//create marker
var marker = new google.maps.Marker({
position: new google.maps.LatLng(lat, lng),
map: map
});
}
}
});
//Create an ElevationService
var elevator = new google.maps.ElevationService;
displayPathElevation(path, elevator, map);
function displayPathElevation(path, elevator, map) {
new google.maps.Polyline({
path: path,
strokeColor: '#0000CC',
strokeOpacity: 0.4,
map: map
});
elevator.getElevationAlongPath({
'path': path,
'samples': 256
}, plotElevation);
}
function plotElevation(elevations, status) {
if (status === 'OK') {
for (var i=0; i < elevations.length; i++) {
console.log(elevations[i].location.lat() );
console.log(elevations[i].location.lng() );
console.log(elevations[i].elevation);
}
}
};
Here are my libs and buttons:
<div id="wrapper">
<label for="Start">Start</label><input id="start" type="textbox"></input><br/>
<label for="End">End</label><input id="end" type="textbox"></input><br/><br/>
<input id="submit" type="button" class="btn btn-dark" value="search" onclick="calcRoute();"><br/><br/>
<div id="chart"></div>
</div>
<div id="map"></div>
<script defer src="https://maps.googleapis.com/maps/api /js?key=MY_API_KEY=initMap"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
javascript google-maps web-mapping google-maps-api google-maps-api-3
javascript google-maps web-mapping google-maps-api google-maps-api-3
edited Jul 24 '18 at 16:48
nmtoken
8,08642866
8,08642866
asked Feb 7 '18 at 13:09
santasanta
313
313
bumped to the homepage by Community♦ 8 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 8 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Try setting a timeout on the displayPathElevation function.
setTimeout(function() {
displayPathElevation(path, elevator, map);
}, 500);
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "79"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f270599%2fgoogle-maps-api-extract-elevation-value-along-route%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try setting a timeout on the displayPathElevation function.
setTimeout(function() {
displayPathElevation(path, elevator, map);
}, 500);
add a comment |
Try setting a timeout on the displayPathElevation function.
setTimeout(function() {
displayPathElevation(path, elevator, map);
}, 500);
add a comment |
Try setting a timeout on the displayPathElevation function.
setTimeout(function() {
displayPathElevation(path, elevator, map);
}, 500);
Try setting a timeout on the displayPathElevation function.
setTimeout(function() {
displayPathElevation(path, elevator, map);
}, 500);
answered Jul 24 '18 at 16:17
bradbrad
1
1
add a comment |
add a comment |
Thanks for contributing an answer to Geographic Information Systems Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f270599%2fgoogle-maps-api-extract-elevation-value-along-route%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown