GVKun编程网logo

javascript – Google Maps API v3在iPad Safari上禁用缩放(谷歌浏览器禁用缩放功能)

1

在这里,我们将给大家分享关于javascript–GoogleMapsAPIv3在iPadSafari上禁用缩放的知识,让您更了解谷歌浏览器禁用缩放功能的本质,同时也会涉及到如何更有效地GoogleM

在这里,我们将给大家分享关于javascript – Google Maps API v3在iPad Safari上禁用缩放的知识,让您更了解谷歌浏览器禁用缩放功能的本质,同时也会涉及到如何更有效地Google Map Api和GOOGLE Search Api整合实现代码_javascript技巧、google maps javascript api v3 如何删除自定义控件、Google Maps JavaScript API v3删除标记、Google.maps.Map Javascript API V3与jquery兼容的内容。

本文目录一览:

javascript – Google Maps API v3在iPad Safari上禁用缩放(谷歌浏览器禁用缩放功能)

javascript – Google Maps API v3在iPad Safari上禁用缩放(谷歌浏览器禁用缩放功能)

我试图弄清楚如何使用Javascript禁用Google Maps API V3上的默认缩放缩放功能.我尝试检测文档上的touchstart事件和嵌套的div但无济于事.任何人有任何想法如何禁用此功能?

笔记
我已经尝试迭代遍历所有DOM元素寻找ontouchstart事件的间隔寻找可能构建黑客的方法,但我似乎找不到(使用我的iPad),所以我不确定它们是如何均匀的正在做.

解决方法

我想出了一个解决方案,因为我的项目是全屏的,下面的代码就可以了.

var tblock = function (e) {
    if (e.touches.length > 1) {
        e.preventDefault()
    }

    return false;
}

document.body.addEventListener("touchmove",tblock,true);

Google Map Api和GOOGLE Search Api整合实现代码_javascript技巧

 

       将GOOGLE MAP API 和 GOOGLE Search API 进行整合,我用面向对象的方式写了一个类,通过传一个经纬度进去,自动通过GOOGLE LOCAL SEARCH获取附近的相关信息。比如餐厅、景点等,反过来标到地图上,并可在任意容器内显示。
下面是源码:

复制代码 代码如下:

/*
*Author:karry
*Version:1.0
*Time:2008-12-01
*KMapSearch 类
*把GOOGLE MAP 和LocalSearch结合。只需要传入MAP\经纬度值,就可以把该经纬度附近的相关本地搜索内容取出来,在地图上标注出来,并可以在指定容器显示搜索结果
*/

(function() {
var markers= new Array();
var KMapSearch=window.KMapSearch= function(map_, opts_) {
this.opts = {
container:opts_.container || "divSearchResult",
keyWord:opts_.keyWord || "餐厅",
latlng: opts_.latlng || new GLatLng(31, 121),
autoClear:opts_.autoClear || true,
icon:opts_.icon || new GIcon(G_DEFAULT_ICON)
};
this.map = map_;
this.gLocalSearch = new google.search.LocalSearch();
this.gLocalSearch.setCenterPoint(this.opts.latlng);
this.gLocalSearch.setResultSetSize(GSearch.LARGE_RESULTSET);
this.gLocalSearch.setSearchCompleteCallback(this, function() {
if (this.gLocalSearch.results) {
var savedResults = document.getElementById(this.opts.container);
if (this.opts.autoClear) {
savedResults.innerHTML = "";
}
for (var i = 0; i savedResults.appendChild(this.getResult(this.gLocalSearch.results[i]));
}
}
});
}
KMapSearch.prototype.getResult = function(result) {
var container = document.createElement("div");
container.className = "list";
var myRadom =(new Date()).getTime().toString()+Math.floor(Math.random()*10000);
container.id=myRadom;
container.innerHTML = result.title + "
地址:" + result.streetAddress;
this.createMarker(new GLatLng(result.lat, result.lng), result.html,myRadom);
return container;
}
KMapSearch.prototype.createMarker = function(latLng, content)
{
var marker = new GMarker(latLng, {icon:this.opts.icon,title:this.opts.title});
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml(content);
});
markers.push(marker);
map.addOverlay(marker);
}
KMapSearch.prototype.clearAll = function() {
for (var i = 0; i this.map.removeOverlay(markers[i]);
}
markers.length = 0;
}
KMapSearch.prototype.execute = function(latLng) {
if (latLng) {
this.gLocalSearch.setCenterPoint(latLng);
}
this.gLocalSearch.execute(this.opts.keyWord);
}
})();

使用方法:
复制代码 代码如下:

var myIcon = new GIcon(G_DEFAULT_ICON);
myIcon.image = "canting.png";
myIcon.iconSize = new GSize(16, 20);
myIcon.iconAnchor = new GPoint(8, 20);
myIcon.shadow = "";
var mapSearch = new KMapSearch(map, {container:"cantingContainer",latlng:initPt,icon:myIcon,keyWord:"餐厅"});
mapSearch.clearAll();
mapSearch.execute();

点击这里查看演示示例:经纬度查询整合本地搜索

google maps javascript api v3 如何删除自定义控件

google maps javascript api v3 如何删除自定义控件

                var location_infos = document.getElementById("location_infos");
        location_infos.index = 1;
        if(location_infos.style.display == "none"){
        location_infos.style.display = "block";
                map.controls[google.maps.ControlPosition.RIGHT_TOP].push(location_infos);
        }else{
        location_infos.style.display = "none";
        //clearOverLays();
        map.controls[google.maps.ControlPosition.RIGHT_TOP].removeAt(1);
        }

Google Maps JavaScript API v3删除标记

Google Maps JavaScript API v3删除标记

我看了很多“相似”的问题,没有一个解决方案/答案似乎适合我,所以我们走了:我正在生成一个简单的谷歌地图,上面有一个标记“onload”我有一个菜单列表a有点像这样

<ul>
<liid="beaches">Item</li>
<liid="towns">Item</li>
<ul>

点击时使用这些数组来标记填充地图

jQuery –

$(".toggle").click(function(){
setMarkers(map,$(this).attr('id'));
});

var beaches = [
['Beach 1',38.285827, 20.611038, 4],
['Beach 2', 38.304958,20.604515, 5],
['Beach 3',38.301691,20.597649, 3]
];

var towns = [
['Town 1',38.343003, 20.535679, 4],
['Town 2',38.339334,20.545807, 5]
];

我的人口函数如下所示:

function setMarkers(map, locations) {
for (var i = 0; i < locations.length; i++) {
var newmarker = locations[i];
var myLatLng = new google.maps.LatLng(newmarker[1], newmarker[2]);
var marker = new google.maps.Marker({
position: myLatLng,
map: map,
title: newmarker[0],
zIndex: newmarker[3]
});
}

但我需要/想要做的是在添加新标记之前先清除所有标记.建议请谢谢

解决方法:

您需要存储标记,并为要从地图中删除的每个标记调用setMap(null).

你可以尝试这样的事情:

var setMarkers = (function() {
    var oldMarkers = null;
    return function(map, locations){
        //Clearing markers, if they exist
        if(oldMarkers && oldMarkers.length !== 0){
            for(var i = 0; i < oldMarkers.length; ++i){
                oldMarkers[i].setMap(null);
            }
        }
        //Adding new markers
        oldMarkers = [];
        for (var i = 0; i < locations.length; i++) {
            var newmarker = locations[i];
            var myLatLng = new google.maps.LatLng(newmarker[1], newmarker[2]);
            var marker = new google.maps.Marker({
               position: myLatLng,
               map: map,
               title: newmarker[0],
               zIndex: newmarker[3]
            });
            oldMarkers.push( marker );
        }
   };
})();

Google.maps.Map Javascript API V3与jquery兼容

Google.maps.Map Javascript API V3与jquery兼容

我试图通过在id =“google_map”div上添加地图来弄清楚为什么会这样做

map = new google.maps.Map(document.getElementById("google_map"), googleMapOptions);

但这不会奏效

var our_map = $("#google_map");
map = new google.maps.Map(our_map, googleMapOptions); 

我在firebug上遇到此控制台错误

TypeError: Argument 1 of Window.getComputedStyle does not implement interface Element.


...(a,b,c){c=c&&1==b;Jt.H?Yn(a[w],c?"":b):(b="alpha(opacity="+Jd(100*b)+")",rn(a[w]...

解决方法:

Map构造函数期望Node作为第一个参数:Map(mapDiv:Node,opts?:MapOptions).

代替

map = new google.maps.Map(our_map, googleMapOptions); 

你必须使用

map = new google.maps.Map(our_map[0], googleMapOptions); 

今天关于javascript – Google Maps API v3在iPad Safari上禁用缩放谷歌浏览器禁用缩放功能的讲解已经结束,谢谢您的阅读,如果想了解更多关于Google Map Api和GOOGLE Search Api整合实现代码_javascript技巧、google maps javascript api v3 如何删除自定义控件、Google Maps JavaScript API v3删除标记、Google.maps.Map Javascript API V3与jquery兼容的相关知识,请在本站搜索。

本文标签:

上一篇iphone – 在UINavigationController上创建后箭头形状leftBarButtonItem(ios15箭头)

下一篇iphone – UINavigationItem titleView的位置