created () {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(position => {
console.log(this.position = position.coords)
var geocoder = new google.maps.Geocoder() //ERROR IN THIS LINE
var googleLatLon = { lat: position.croods.latitude, lng: position.croods.longitude }
geocoder.geocode({ 'location': googleLatLon }, (results, error) => {
console.log(results[0].address_components[2].long_name + ', ' + results[0].address_components[3].long_name + ', ' + results[0].address_components[4].long_name + ', ' + results[0].address_components[5].long_name)
})
})
}
}
的index.html
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="http://maps.google.com/maps/api/js"></script>
<link rel="manifest" href="<%= htmlWebpackPlugin.files.publicPath %>static/manifest.json">
我在index.html中添加了google的地图api,上面的代码来自App.vue。我哪里出错了?
答案 0 :(得分:0)
您正在编写错误的变量名称
position.croods
。
它应该是position.coords
。
var geocoder = new google.maps.Geocoder()