谷歌地图GetLocation返回字符串
Google Map GetLocation Return String
我有一段代码,
geocoder = new GClientGeocoder();
var state;
function addAddressToMap(response) {
if (!response || response.Status.code != 200) {
alert("Sorry, we were unable to geocode that address");
}
else {
place = response.Placemark[0];
state = place.AddressDetails.Country.AdministrativeArea.AdministrativeAreaName;
}
}
// showLocation() is called when you click on the Search button
// in the form. It geocodes the address entered into the form
// and adds a marker to the map at that location.
function showLocation() {
var address = "mutiara damansara";
geocoder.getLocations(address, addAddressToMap);
return state;
}
好的,更新了代码。我尝试实例化showLocation()
,但addAddressToMap
函数没有更新变量state
。
感谢
您更新的代码有助于更好地查看图片。
看起来addAddressToMap()
正在从函数参数中期待一个响应变量。
当geocoder.getLocations(address,addAddressToMap)
调用它时,没有传递任何响应。
因此,第一个if
语句!response
为真,而state
保持未设置。
要修复此问题,您需要在调用addAddressToMap()
时传递一些内容。它看起来像是脚本中其他地方的XMLHttpRequest
(Ajax(对象。
相关文章:
- PHP strtotime()为JavaScript日期字符串返回false
- 如何将表单数据传递给PHP并将json字符串返回给Javascript
- 解析JSON字符串返回未定义的结果
- Javascript:解析csv中的字符串返回NaN(不是数字)
- 使用$se.trustAsHtml呈现字符串返回未定义的结果
- 将字符串返回到类型为“0”的输出字段;数字“;针对用户错误javascript
- 如何使用一些变量参数从javascript函数调用 asp.net C#函数并从C#函数获取字符串返回
- 函数:根据字符串中是否存在子字符串返回 True/False
- 如何使用 JavaScript 区分布尔值和字符串返回值
- 将 React 的方法 'return' 作为字符串返回
- 调用不带括号的函数会将整个函数作为字符串返回
- 如何在 ajax 调用中接受来自控制器的字符串返回
- Jquery - 匹配动态日期字符串返回使用长度的匹配量
- json_encode使用 jquery.get() 发布数据时将数组作为字符串返回
- 缓冲区中的nodejs解码字符串返回多行字符串
- 如何将关联数组键作为字符串返回
- python's mechanize和forms:javascript字符串返回
- 将呈现的ejs视图作为服务内的html字符串返回
- CSV文件作为单个字符串返回
- jQuery中的HTML字符串返回错误