这是我正在使用的代码:http: //jsfiddle.net/DYfbg/12/
如果您单击“地图”,然后尝试输入地名,它会为您提供自动完成建议。然后,如果您单击这些建议之一,它会在警报框中告诉您坐标。
我想要做的是在单击自动完成选项时捕获输入框中的内容,然后将其存储为变量。然后在警报框中,连同坐标,我想将输入框变量打印到其中。
我知道这一切听起来很简单,但我是 javascript 新手,所以我非常感谢一些输入。
这是代码段:
google.maps.event.addListener(autocomplete, 'place_changed', function() {
    var place = autocomplete.getPlace();
    **// Store input box as variable**
    if (!place.geometry) {
        current_place = null;
        alert('Cannot find place');
        return;
    } else {
        current_place = place;
        alert('Place is at:' + place.geometry.location);
        **// Print input box varaible aswell**
    } });
编辑:这是尽可能接近而不会卡住:
    // Set Autocomplete Location Variable equal to #loc input
    $("#loc").val(ac_location);
    // Print Autocomplete Variable
    alert(ac_location);