- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个谷歌搜索和显示标记的示例。我试图让谷歌显示标记 map ,然后显示一个搜索栏,供用户输入城市或邮政编码并显示带有标记的该区域。我关注了,Store Locator in google maps, input zip code and display markers on map and sidebar
一切都很好,但是本地图首次加载时,它不会显示任何标记。仅当您搜索时。我需要一直打开这些标记。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Store Locate</title>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=false&libraries=places&key=AIzaSyDOorkShHO1xhw2zbjz-OZdSKP-xQ65AS0"></script>
<style>
#pac-input {
background-color: #fff;
font-family: Roboto;
font-size: 15px;
font-weight: 300;
margin-left: 12px;
padding: 0 11px 0 13px;
text-overflow: ellipsis;
width: 400px;
}
#pac-input:focus {
border-color: #4d90fe;
}
.pac-container {
font-family: Roboto;
}
#type-selector {
color: #fff;
background-color: #4d90fe;
padding: 5px 11px 0px 11px;
}
#type-selector label {
font-family: Roboto;
font-size: 13px;
font-weight: 300;
}
</style>
<script type="text/javascript">
var side_bar_html = "";
// arrays to hold copies of the markers and html used by the side_bar
var gmarkers = [];
var marker;
var map = null;
var t=1;
function initialize() {
// create the map
var myOptions = {
center: new google.maps.LatLng(35.467560, -97.516428),
zoom:6,
disableDefaultUI: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);
google.maps.event.addListener(map, 'click', function() {
infowindow.close();
});
initSearchBox(map, 'pac-input');
}//----------------INIT END--------------------
var infowindow = new google.maps.InfoWindow(
{
size: new google.maps.Size(150,50)
});
// This function picks up the click and opens the corresponding info window
function myclick(i) {
google.maps.event.trigger(gmarkers[i], "click");
}
function initSearchBox(map, controlId) {
// Create the search box and link it to the UI element.
var input = (document.getElementById(controlId));
map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);
var searchBox = new google.maps.places.SearchBox(input);
// [START region_getplaces]
// Listen for the event fired when the user selects an item from the
// pick list. Retrieve the matching places for that item.
google.maps.event.addListener(searchBox, 'places_changed', function () {
var places = searchBox.getPlaces();
if (places.length == 0) {
return;
}
//get first place
var place = places[0];
var infowindow = new google.maps.InfoWindow(
{
size: new google.maps.Size(150,50),
content : place.info
});
// Add markers to the map
// Set up the markers with info windows
// add the points
var point = new google.maps.LatLng(35.979088,-96.112985);
var marker = createMarker(point,"Firestone, Oklahoma City<br>211 411 2311")
var point = new google.maps.LatLng(38.0409333,23.7954601);
var marker = createMarker(point,"Nespresso S.A.","<b>Nespresso S.A.</b><br>Agiou Thoma 27,15124,Marousi")
var point = new google.maps.LatLng(38.0473031,23.8053483);
var marker = createMarker(point,"Regency Entertainment","<b>Regency Entertainment</b><br>Agiou Konstantinou 49,15124,Marousi <br>210 614 9800")
var point = new google.maps.LatLng(38.050986,23.8084322);
var marker = createMarker(point,"Just4U","<b>Just4U</b> <br>Dimitriou Gounari 84, 15124, Marousi<br>210 614 1923")
var point = new google.maps.LatLng(38.0400533,23.8011982);
var marker = createMarker(point,"Ekka Cars S.A.","<b>Ekka</b> <br>Leoforos Kifisias 79,15124,Marousi<br>210 349 8000")
// put the assembled side_bar_html contents into the side_bar div
document.getElementById("side_bar").innerHTML = side_bar_html;
t -=1;//This is so if you search again, it doesn't display again in sidebar
map.fitBounds(place.geometry.viewport);
});
}
// A function to create the marker and set up the event window function
function createMarker(latlng, name, html) {
var contentString = html;
var marker = new google.maps.Marker({
position: latlng,
map: map,
//zIndex: Math.round(latlng.lat()*-100000)<<5
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(contentString);
infowindow.open(map,marker);
});
// save the info we need to use later for the side_bar
gmarkers.push(marker);
// add a line to the side_bar html
side_bar_html += '<a href="javascript:myclick(' + (gmarkers.length-1) + ')">' + name + '<\/a><br>';
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body style="margin:0px; padding:0px;" >
<input id="pac-input" class="controls" type="text" placeholder="City, State or Zip Code">
<div id="map_canvas" style="width: 550px; height: 450px"></div>
</body>
</html>
最佳答案
这是因为您要在 places_changed
事件上添加标记。只需将标记创建代码移至 initialize
函数中即可。
var point = new google.maps.LatLng(35.979088,-96.112985);
var marker = createMarker(point,"Firestone, Oklahoma City<br>211 411 2311");
var point = new google.maps.LatLng(38.0409333,23.7954601);
var marker = createMarker(point,"Nespresso S.A.","<b>Nespresso S.A.</b><br>Agiou Thoma 27,15124,Marousi");
var point = new google.maps.LatLng(38.0473031,23.8053483);
var marker = createMarker(point,"Regency Entertainment","<b>Regency Entertainment</b><br>Agiou Konstantinou 49,15124,Marousi <br>210 614 9800");
var point = new google.maps.LatLng(38.050986,23.8084322);
var marker = createMarker(point,"Just4U","<b>Just4U</b> <br>Dimitriou Gounari 84, 15124, Marousi<br>210 614 1923");
var point = new google.maps.LatLng(38.0400533,23.8011982);
var marker = createMarker(point,"Ekka Cars S.A.","<b>Ekka</b> <br>Leoforos Kifisias 79,15124,Marousi<br>210 349 8000");
您也不需要每次都执行 var
来更新您的点和标记。
var point = new google.maps.LatLng(35.979088,-96.112985);
var marker = createMarker(point,"Firestone, Oklahoma City<br>211 411 2311");
point = new google.maps.LatLng(38.0409333,23.7954601);
marker = createMarker(point,"Nespresso S.A.","<b>Nespresso S.A.</b><br>Agiou Thoma 27,15124,Marousi");
point = new google.maps.LatLng(38.0473031,23.8053483);
marker = createMarker(point,"Regency Entertainment","<b>Regency Entertainment</b><br>Agiou Konstantinou 49,15124,Marousi <br>210 614 9800");
point = new google.maps.LatLng(38.050986,23.8084322);
marker = createMarker(point,"Just4U","<b>Just4U</b> <br>Dimitriou Gounari 84, 15124, Marousi<br>210 614 1923");
point = new google.maps.LatLng(38.0400533,23.8011982);
marker = createMarker(point,"Ekka Cars S.A.","<b>Ekka</b> <br>Leoforos Kifisias 79,15124,Marousi<br>210 349 8000");
所以你的initialize
函数看起来像这样:
function initialize() {
// create the map
var myOptions = {
center: new google.maps.LatLng(35.467560, -97.516428),
zoom:6,
disableDefaultUI: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"),myOptions);
google.maps.event.addListener(map, 'click', function() {
infowindow.close();
});
var point = new google.maps.LatLng(35.979088,-96.112985);
var marker = createMarker(point,"Firestone, Oklahoma City<br>211 411 2311");
point = new google.maps.LatLng(38.0409333,23.7954601);
marker = createMarker(point,"Nespresso S.A.","<b>Nespresso S.A.</b><br>Agiou Thoma 27,15124,Marousi");
point = new google.maps.LatLng(38.0473031,23.8053483);
marker = createMarker(point,"Regency Entertainment","<b>Regency Entertainment</b><br>Agiou Konstantinou 49,15124,Marousi <br>210 614 9800");
point = new google.maps.LatLng(38.050986,23.8084322);
marker = createMarker(point,"Just4U","<b>Just4U</b> <br>Dimitriou Gounari 84, 15124, Marousi<br>210 614 1923");
point = new google.maps.LatLng(38.0400533,23.8011982);
marker = createMarker(point,"Ekka Cars S.A.","<b>Ekka</b> <br>Leoforos Kifisias 79,15124,Marousi<br>210 349 8000");
initSearchBox(map, 'pac-input');
}
关于javascript - Google map 商店定位器和搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48710364/
这里有点绝望。我有一个使用由 Node 8.12.0 驱动的 AngularJS (5.4.1) 的遗留测试套件。我想调试一些测试,但似乎不可能。 测试中启用了控制流,因此我按照 the protra
我想知道是否有任何方法可以在我的 html 中定义一个区域(div 标签?),其中模板根据它绑定(bind)到的对象而变化? 假设我们有一个 ShellView/ShellViewModel List
我在 WebDriver 中自动化报告提交过程,报告有多个页面,所有页面中都会有 Next按钮进入下一页。 下一个按钮有一个跟随定位器, Next 问题是所有Next报告中的按钮具有相同的定位器,因为
如果我想找一个也有特定类的中继器怎么办?或者,如果我想查找包含文本的绑定(bind)? 如果我想通过 repeater OR CSS 选择器(匹配具有特定 repeater 表达式 OR 的元素,例如
在我当前的项目中,我们从 XSD 文件生成 JAXB bean。我们需要有关 bean 的行号信息(除了 XSD 验证错误!)所以我使用了此处指定的 -Xlocator 选项: http://java
我有一个 Angular 应用程序,我在其中放置自定义 html 属性(“data-testid='saveButton'”)以用于识别,例如按钮、输入等Protractor 对此没有内置定位器:xp
我是 Protractor 和 E2E 测试的新手,想确定我的 CSS 定位器方法是否适用于同一类的相同元素。 我有一个 HTML Fiddle here它描绘了一个包含两个 div 元素的网页,每个
Delete Edit 我想为“编辑”按钮编写一个 CSS 定位器。它在 [data-credit-card-index="1"] 部分下...那里会有更多的信用卡...所以我必须使
我有 3 个下拉列表,它们不是选择类。所以我需要点击每个元素的向下箭头键。这些箭头键的样式相同:.Select-arrow(使用的火路) HTML: NicknameEx. LarrySaint, L
我正在尝试对我的网站进行测试。在某些用户表单上遇到问题。诀窍是,表单中文本字段的数量因用户选项而异(代码中存在禁用的文本字段,但具有样式 标记),所以我'我试图找到比逐个定位每个元素并用 try/e
I have a problem with ng-binding locator in Protractor code: some_link I tried to use: element(by
假设我正在#myPage 元素下寻找一些 div 元素。 我的目标是使用 CSS 选择器并将搜索限制为 #myPage 后代。 使用 Selenium XPath 定位器,我可以编写如下内容: Web
如何以文本“步骤1.设定 self 开发的方向”为起点,选择Xpath定位器到复选框? 为方便起见,您可以从此处复制文本: pdp-action-item-header__checkbox pdp-a
我需要简要介绍一下根据 IP 地址将内容限制在特定国家/地区背后的弱点。 除了使用位于另一个国家的代理服务器,你能想出另一种方法来绕过这样的系统吗? 最佳答案 基本上,任何使用中介的解决方案都是代理。
我已经让应用程序在 textview 中显示收件箱中当前的所有短信。为了做到这一点,我必须包含 URI。我正在尝试测试我拥有但未通过我的移动运营商(版本)注册的其他手机,因为它们不支持我拥有的手机,因
需要您的帮助来为 Selenium 中的 findElements 方法找到正确的 XPath。详情如下: 网址 - http://www.cleartrip.com/hotels/info/hote
我正在努力掌握我的 xPath 发现,但我遇到了一个问题。我的目标是从表中获取复选框。您能给我一些建议,应该如何始终设置定位器吗? 假设我的目标是指向需要单击的复选框 的input。 首先我尝试了非常
我正在尝试使用 Spring Data Gemfire 设置 Gemfire 集群。 我可以通过 gfsh 启动一个定位器,我可以通过 Spring 启动一个服务器。 问题是,我找不到通过 Sprin
我正在使用基于模型的表单,我的表单如下所示: Submit 我想写一个 Protractor 规范来测试登录。我喜欢在我的规范中做类似下面的事情: element(by.f
有没有一种优雅的方式来获取我已经找到/识别的 Selenium WebElement 的 By 定位器? 要明确这个问题:我希望使用“按定位器”来查找元素。在这种情况下,我不对特定属性或特定定位器(如
我是一名优秀的程序员,十分优秀!