I have read some issues with calculate distance on google maps API but still not working for me. Here is my code:
function initMap() {
var loc1 = new google.maps.LatLng(37.772323, -122.214897);
var loc2 = new google.maps.LatLng(34.1633766,-81.6487862);
console.log(google.maps.geometry.sphericalputeDistanceBetween(loc1,loc2));
}
This is how I call library:
<script src=",places&key=MY_KEY&libraries=places&callback=initMap" async defer></script>
But I still get error: Uncaught TypeError: Cannot read property 'spherical' of undefined at initMap
What I'm doing wrong? Do I have to enable some custom API?
I have read some issues with calculate distance on google maps API but still not working for me. Here is my code:
function initMap() {
var loc1 = new google.maps.LatLng(37.772323, -122.214897);
var loc2 = new google.maps.LatLng(34.1633766,-81.6487862);
console.log(google.maps.geometry.spherical.puteDistanceBetween(loc1,loc2));
}
This is how I call library:
<script src="https://maps.googleapis./maps/api/js?libraries=geometry,places&key=MY_KEY&libraries=places&callback=initMap" async defer></script>
But I still get error: Uncaught TypeError: Cannot read property 'spherical' of undefined at initMap
What I'm doing wrong? Do I have to enable some custom API?
Share Improve this question asked May 5, 2017 at 9:01 general666general666 1,0392 gold badges16 silver badges32 bronze badges2 Answers
Reset to default 7You have the 'libraries' parameter in your src url twice.
Remove the second one: &libraries=places
...and keep the first one: &libraries=geometry,places
<script src="https://maps.googleapis./maps/api/js?libraries=geometry,places&key=MY_KEY&callback=initMap" async defer></script>
There is a problem with request url, libraries parameter duplicates.
<script src="https://maps.googleapis./maps/api/js?libraries=geometry,places&key=MY_KEY&callback=initMap" async defer></script>
In order to use spherical class you have to include 'geometry' into requesting libraries list - check documentation :
// This example requires the Geometry library. Include the libraries=geometry
// parameter when you first load the API. For example:
// <script src="https://maps.googleapis./maps/api/js?key=YOUR_API_KEY&libraries=geometry">
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742288993a4415844.html
评论列表(0条)