Google Maps API extract elevation value along routeExport 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
Could Giant Ground Sloths have been a Good Pack Animal for the Ancient Mayans
How to manage monthly salary
What does 'script /dev/null' do?
Is it legal to have the "// (c) 2019 John Smith" header in all files when there are hundreds of contributors?
COUNT(id) or MAX(id) - which is faster?
Why do UK politicians seemingly ignore opinion polls on Brexit?
Where to refill my bottle in India?
extract characters between two commas?
How is it possible for user's password to be changed after storage was encrypted? (on OS X, Android)
What is the command to reset a PC without deleting any files
Symmetry in quantum mechanics
Is there a way to make member function NOT callable from constructor?
How can I fix this gap between bookcases I made?
Copycat chess is back
How to deal with fear of taking dependencies
Can I legally use front facing blue light in the UK?
What do the Banks children have against barley water?
Shall I use personal or official e-mail account when registering to external websites for work purpose?
Prime joint compound before latex paint?
Manga about a female worker who got dragged into another world together with this high school girl and she was just told she's not needed anymore
Piano - What is the notation for a double stop where both notes in the double stop are different lengths?
Does it makes sense to buy a new cycle to learn riding?
Was there ever an axiom rendered a theorem?
What are the advantages and disadvantages of running one shots compared to campaigns?
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
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
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
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
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
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