Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/433.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从谷歌地理代码jquery抓取国家_Javascript_Jquery_Google Maps_Google Maps Api 3 - Fatal编程技术网

Javascript 从谷歌地理代码jquery抓取国家

Javascript 从谷歌地理代码jquery抓取国家,javascript,jquery,google-maps,google-maps-api-3,Javascript,Jquery,Google Maps,Google Maps Api 3,我得到了一个jquery脚本的帮助,该脚本将通过谷歌地理编码系统对键入的位置进行地理编码 我需要在country字段中输入country值的简短名称。就我的一生而言,我无法思考我应该如何整合,我尝试的一切都没有回报。请任何人就实现这一目标的正确方法提供一些见解 JSFIDDLE: 根据我需要的信息: results[]: { types[]: string, formatted_address: string, address_components[]: { short_name:

我得到了一个jquery脚本的帮助,该脚本将通过谷歌地理编码系统对键入的位置进行地理编码

我需要在country字段中输入country值的简短名称。就我的一生而言,我无法思考我应该如何整合,我尝试的一切都没有回报。请任何人就实现这一目标的正确方法提供一些见解

JSFIDDLE:

根据我需要的信息:

results[]: {
 types[]: string,
 formatted_address: string,
 address_components[]: {
   short_name: string,
   long_name: string,
   types[]: string
 },
 geometry: {
   location: LatLng,
   location_type: GeocoderLocationType
   viewport: LatLngBounds,
   bounds: LatLngBounds
 }
}

分析结果,查找一个具有“country”类型的

类似的方法应该可以工作(未经测试):

results[]: {
 types[]: string,
 formatted_address: string,
 address_components[]: {
   short_name: string,
   long_name: string,
   types[]: string
 },
 geometry: {
   location: LatLng,
   location_type: GeocoderLocationType
   viewport: LatLngBounds,
   bounds: LatLngBounds
 }
}
geocoder.geocode({ address: query }, function(results, status) {
  if( status === google.maps.GeocoderStatus.OK ) {
    lat.val(results[0].geometry.location.lat());
    lng.val(results[0].geometry.location.lng());
    var address = results[0].address_components;
    for (var p = address.length-1; p >= 0; p--) {
      if (address[p].types.indexOf("country") != -1) {
      // do something useful with the country...
      // document.getElementById('postcode').innerHTML= address[p].long_name;
      }
    }
    lastResult = true; // success!
  } else {
    alert("Sorry - We couldn't find this location. Please try an alternative");
    lastResult = false; // failure!
  }
  callback(lastResult); // send the result back
});