中心地图到界限不起作用

时间:2015-09-02 05:59:36

标签: javascript google-maps-api-3

我试图将地图居中以适合所有标记。有很多这方面的例子,看起来相当容易,但我无法让它发挥作用。谁能看到我做错了什么?

地图可以在这里进行测试:http://www.lymphoedema.org.au/the-register/find-a-practitioner-test/ [[搜索范围在40公里以内;然后点击地图查看地图]]。

地图会立即缩放,标记位于地图的左上角。

谁能看到我做错了什么?

谢谢!

display:block

1 个答案:

答案 0 :(得分:0)

从引导选项卡中测试后,您的代码工作正常。所以我想调整大小的触发器在这个问题上有一些含义。

尝试这种方式:

void KeyUpTest::App::OnCharacterReceived(Windows::UI::Core::CoreWindow ^sender, Windows::UI::Core::CharacterReceivedEventArgs ^args) { bool iskey = false; int keycode = args->KeyCode; if (keycode == 65) { iskey = true; } } 功能范围之外(您定义boundsinitialize变量的位置)声明您的marker变量。顺便说一下,你也错过了markers变量声明。

map

然后在引导程序显示的事件中也适合边界:

var markers = [];
var marker;
var bounds = new google.maps.LatLngBounds();
var map; // missing in your original code

不要忘记在此处删除// trigger map resize event when map tab is displayed $("#mapTab").on('shown.bs.tab', function() { google.maps.event.trigger(map, 'resize'); map.fitBounds(bounds); // add this line to your code }); 声明:

var

现在应该是:

//set map bounds
var bounds = new google.maps.LatLngBounds();

这是未经测试的,但这是我现在所能想到的。让我知道它是否有效。

相关问题