Javascript Google Maps v3-将圆设置为设置位置(位置)

Javascript Google Maps v3-将圆设置为设置位置(位置),javascript,google-maps,Javascript,Google Maps,尝试在使用“位置”库搜索的位置周围创建一个具有静态半径的圆。与此类似。唯一的区别是我只需要圆的半径是静态的 以下是我尝试过的(我是gmaps新手): var映射选项={ 中心:新google.maps.LatLng(37.7831,-122.4039), 缩放:12, mapTypeId:google.maps.mapTypeId.ROADMAP }; var map=new google.maps.map(document.getElementById('map-canvas'),mapOpt

尝试在使用“位置”库搜索的位置周围创建一个具有静态半径的圆。与此类似。唯一的区别是我只需要圆的半径是静态的

以下是我尝试过的(我是gmaps新手):

var映射选项={
中心:新google.maps.LatLng(37.7831,-122.4039),
缩放:12,
mapTypeId:google.maps.mapTypeId.ROADMAP
};
var map=new google.maps.map(document.getElementById('map-canvas'),mapOptions);
变量A选项={
类型:[“机构”]
};
var autocomplete=new google.maps.places.autocomplete(document.getElementById('autocomplete'),acOptions);
autocomplete.bindTo('bounds',map);
var infoWindow=new google.maps.infoWindow();
变量循环次数={
strokeColor:“#FF0000”,
笔划不透明度:0.8,
冲程重量:2,
填充颜色:'#FF0000',
不透明度:0.35,
};
var cityCircle=新的google.maps.Circle(CircleOptions);
google.maps.event.addListener(自动完成,'place\u changed',函数(){
infoWindow.close();
citycircle.close();
var place=autocomplete.getPlace();
if(place.geometry.viewport){
map.fitBounds(place.geometry.viewport);
}否则{
地图。设置中心(地点。几何。位置);
map.setZoom(17);
}
infoWindow.setContent(''+place.name+'
'); infoWindow.setPosition(place.geometry.location); 打开(地图); cityCircle.setPosition(信息窗口); });
下面的代码不正确。.setPosition方法需要一个google.maps.LatLng对象,而不是一个infoWindow。您应该从API中获得javascript错误或消息

cityCircle.setPosition(infoWindow);
这应该有效(圆没有位置,它有一个中心):

您还需要定义圆的半径

在自动完成服务返回的位置放置圆圈的代码:

    google.maps.event.addListener(autocomplete, 'place_changed', function() {
      infoWindow.close();
      var place = autocomplete.getPlace();
      if (place.geometry.viewport) {
        map.fitBounds(place.geometry.viewport);
      } else {
        map.setCenter(place.geometry.location);
        map.setZoom(17);
      }
      infoWindow.setContent('<div><strong>' + place.name + '</strong><br>');
      infoWindow.setPosition(place.geometry.location);
      infoWindow.open(map);
      cityCircle.setMap(map);
      cityCircle.setCenter(place.geometry.location);
      map.fitBounds(cityCircle.getBounds());
    });

下面的代码不正确。.setPosition方法需要一个google.maps.LatLng对象,而不是一个infoWindow。您应该从API中获得javascript错误或消息

cityCircle.setPosition(infoWindow);
这应该有效(圆没有位置,它有一个中心):

您还需要定义圆的半径

在自动完成服务返回的位置放置圆圈的代码:

    google.maps.event.addListener(autocomplete, 'place_changed', function() {
      infoWindow.close();
      var place = autocomplete.getPlace();
      if (place.geometry.viewport) {
        map.fitBounds(place.geometry.viewport);
      } else {
        map.setCenter(place.geometry.location);
        map.setZoom(17);
      }
      infoWindow.setContent('<div><strong>' + place.name + '</strong><br>');
      infoWindow.setPosition(place.geometry.location);
      infoWindow.open(map);
      cityCircle.setMap(map);
      cityCircle.setCenter(place.geometry.location);
      map.fitBounds(cityCircle.getBounds());
    });

下面的代码不正确。.setPosition方法需要一个google.maps.LatLng对象,而不是一个infoWindow。您应该从API中获得javascript错误或消息

cityCircle.setPosition(infoWindow);
这应该有效(圆没有位置,它有一个中心):

您还需要定义圆的半径

在自动完成服务返回的位置放置圆圈的代码:

    google.maps.event.addListener(autocomplete, 'place_changed', function() {
      infoWindow.close();
      var place = autocomplete.getPlace();
      if (place.geometry.viewport) {
        map.fitBounds(place.geometry.viewport);
      } else {
        map.setCenter(place.geometry.location);
        map.setZoom(17);
      }
      infoWindow.setContent('<div><strong>' + place.name + '</strong><br>');
      infoWindow.setPosition(place.geometry.location);
      infoWindow.open(map);
      cityCircle.setMap(map);
      cityCircle.setCenter(place.geometry.location);
      map.fitBounds(cityCircle.getBounds());
    });

下面的代码不正确。.setPosition方法需要一个google.maps.LatLng对象,而不是一个infoWindow。您应该从API中获得javascript错误或消息

cityCircle.setPosition(infoWindow);
这应该有效(圆没有位置,它有一个中心):

您还需要定义圆的半径

在自动完成服务返回的位置放置圆圈的代码:

    google.maps.event.addListener(autocomplete, 'place_changed', function() {
      infoWindow.close();
      var place = autocomplete.getPlace();
      if (place.geometry.viewport) {
        map.fitBounds(place.geometry.viewport);
      } else {
        map.setCenter(place.geometry.location);
        map.setZoom(17);
      }
      infoWindow.setContent('<div><strong>' + place.name + '</strong><br>');
      infoWindow.setPosition(place.geometry.location);
      infoWindow.open(map);
      cityCircle.setMap(map);
      cityCircle.setCenter(place.geometry.location);
      map.fitBounds(cityCircle.getBounds());
    });


像“信息窗口”这样的操作是否有意义?相反,打开(地图,城市圆圈)?哎呀,别忘了圆圈有一个中心,而不是一个位置。你写道:
像infoWindow.open(地图,cityCircle)这样做有意义吗?
-请不要猜测,阅读文档,在某一点上,第二个位置上唯一可能出现的东西是google.maps.Marker,我想这已经改变了,但我认为它不适用于圆。像
infoWindow.open(map,cityCircle)
这样的操作有意义吗?哎呀,别忘了圆有一个中心,而不是一个位置。你写道:
像infoWindow.open(地图,cityCircle)这样做有意义吗?
-请不要猜测,阅读文档,在某一点上,第二个位置上唯一可能出现的东西是google.maps.Marker,我想这已经改变了,但我认为它不适用于圆。像
infoWindow.open(map,cityCircle)
这样的操作有意义吗?哎呀,别忘了圆有一个中心,而不是一个位置。你写道:
像infoWindow.open(地图,cityCircle)这样做有意义吗?
-请不要猜测,阅读文档,在某一点上,第二个位置上唯一可能出现的东西是google.maps.Marker,我想这已经改变了,但我认为它不适用于圆。像
infoWindow.open(map,cityCircle)
这样的操作有意义吗?哎呀,别忘了圆有一个中心,而不是一个位置。你写道:
像infoWindow.open(地图,cityCircle)这样做有意义吗?
-请不要猜测,阅读文档,在某一点上,第二个位置上唯一可能出现的东西是一个google.maps.Marker,我想这已经改变了,但我认为它不会与圆圈一起工作。