[英]Google Maps popup on text-box click?
I have some code for google maps autofilling a text box with Latitude and Longitude when you click on the map.我有一些谷歌地图代码,当你点击地图时,它会自动填充一个带有纬度和经度的文本框。
Now I would like to know if there's a way you can have the map appear in a popup?现在我想知道是否有办法让地图出现在弹出窗口中? I searched for "google map" popup frame and things along the same line but I could not find anything.
我搜索了“谷歌地图”弹出框和同一条线上的东西,但我找不到任何东西。
For instance: Let's assume there is a textbox with id "Location" .例如:假设有一个 ID 为"Location"的文本框。 Once you click on the textbox, a google map popup will appear where you can click and the coordinates will be entered automatically into "Location" (already have this part of the code).
单击文本框后,将出现一个谷歌地图弹出窗口,您可以在其中单击,坐标将自动输入到“位置”中(已经有这部分代码)。 If you click anywhere on the screen behind the popup, the google map popup must disappear.
如果您单击弹出窗口后面屏幕上的任意位置,谷歌地图弹出窗口必须消失。
What I had in mind was the google map is hidden;我想到的是谷歌地图是隐藏的; and once there is an "onclick" event for the textbox, it will show the popup and the user can choose the location.
一旦文本框出现“onclick”事件,它将显示弹出窗口,用户可以选择位置。
I will add the code.我会添加代码。
var map; var marker = null; function initialize() { var mapOptions = { zoom: 5, disableDefaultUI: false, center: new google.maps.LatLng(21.268899719967695, 39.2266845703125), mapTypeId: google.maps.MapTypeId.ROADMAP }; map = new google.maps.Map(document.getElementById('map'), mapOptions); google.maps.event.addListener(map, 'click', function(event) { $("#Coordinate1").val(event.latLng.lat() + ", " + event.latLng.lng()); $("#Coordinate1").select(); if (marker) { marker.setMap(null); } marker = new google.maps.Marker({ position: event.latLng, map: map}); }); } google.maps.event.addDomListener(window, 'load', initialize);
#map { width:350px; height:200px; } #Coordinate1{ text-align:center; border:1px #ccc solid; }
<div id="map"></div> <input type="text" id="Coordinate1" value="Latitude, Longitude">
Thank you.谢谢你。
You should consider implementing a page where you have that map separately.您应该考虑实现一个单独拥有该地图的页面。 Use it as an
iframe
inside the main page and show/hide its container whenever you need to do that.将其用作主页内的
iframe
,并在需要时显示/隐藏其容器。 So, steps to solve the problem:所以,解决问题的步骤:
iframe
pointing to the map pageiframe
iframe
page and main page via Javascriptiframe
页面和主页之间的通信
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.