drbmhd9583
2017-11-28 16:59
浏览 84
已采纳

在地图上选择一个点并将其显示在输入上[关闭]

I would like to know if there's a way to show a map on a form, select a point on that map and display the address in an input like a textbox and viceversa (to write an address in that textbox and show a point on the map), and save that address in a variable.

It would be very useful something like an <input type="map"> with its own properties but I don't know if that exists.

图片转代码服务由CSDN问答提供 功能建议

我想知道是否有办法在表单上显示地图,在该地图上选择一个点, 在输入中显示地址,如文本框和反之(在该文本框中写入地址并在地图上显示一个点),并将该地址保存在变量中。

它将是 非常有用的东西,比如&lt; input type =“map”&gt; 有自己的属性,但我不知道是否存在。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douxian1923 2017-11-28 19:44
    已采纳

    Ok so I found a solution, in Google Maps API there's an example that displays a map with a search box: https://developers.google.com/maps/documentation/javascript/examples/places-searchbox?hl=es, I created a function that obtains the value of the search box and displays it into an input of type text:

    function getAddress(){
    var address = document.getElementById('pac-input').value;
    document.getElementById('address').value = address;
    }
    

    Where "pac-input" is the id of the search box and "address" is the id of the input that I created.

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题