TypeError:这是未定义的 [英] TypeError: this is undefined
本文介绍了TypeError:这是未定义的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从html5位置函数获取用户的纬度和经度.之后,使用Google Maps API,我想获取用户的当前位置名称.这是我在jquery中编写的代码.但是我遇到了错误
I am trying to get user's latitude and longitude from the html5 location functions. After that using google maps API i want to get user's current location name. This is a code i wrote in jquery. But i am experiencing an error
"TypeError:这是未定义的"
"TypeError: this is undefined "
这里出了什么问题?我错过了什么吗?
What is going wrong here ? Have I missed something ?
function getLocation() //getting the users location
{
alert("inside show getlocation");
var locationerror = document.getElementById('locationerror');
if(navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition);
}
else
{
locationerror.innerHTML = "Please enable current location in your browser to get best results. Click <a href = 'https://www.google.co.in/search?q=enable+current+location+in+browser'>here<a> for help.";
}
};
getLocation();
function showPosition(position) //get user's current location name
{
alert("inside show position");
mylat = position.coords.latitude;
mylong = position.coords.longitude;
var latlng2 = new google.maps.LatLng(mylat,mylong);
alert(latlng2);
geocoder = new google.maps.Geocoder();
if (geocoder)
{
var apilink2 = "http://maps.googleapis.com/maps/api/geocode/json?";
$.ajax(
{
type: "GET",
url: apilink2,
data: {
latlng: latlng2,
sensor: true
},
dataType: "jsonp"
}).done(function(response)
{
alert("done");
var currentlocationname = response[0].formatted_address;
if( typeof response[0].currentlocationname == 'undefined' )
{
$('#locationerror').innerHTML = "Can't get your current location.";
}
});
alert(currentlocationname);
推荐答案
当然,这是错误的.您应该使用 jQuery()
而不是 $()
Absolutely, It 's error. You should use jQuery()
instead of $()
这篇关于TypeError:这是未定义的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文