Hi I am having issues inserting a map from google maps and using the send framework.
嗨,我有问题从谷歌地图插入地图和使用发送框架。
My issue is similar to Question 921811
我的问题类似于问题921811
However when adding the script to my view I am getting the googlemaps api in twice and no map being rendered by the view.
但是,当我将脚本添加到我的视图中时,我将获得两次googlemaps api,并且视图不会呈现任何地图。
This is what I am adding to the view script
这是我添加到视图脚本的内容
<?php
$this->headScript()->appendFile('http://maps.google.com/maps?file=api&;v=2&;sensor=true&;key=ABQIAAAAHSJ3TgOTyvA1VzwU8g4Y7RT2yXp_ZAY8_ufC3CFXhHIE1NvwkxRmCy1h3nGv3n46kcqaFljsimqfWw');
$this->headScript()->appendScript(' var map = null;
var geocoder = null;
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(37.4419, -122.1419), 13);
geocoder = new GClientGeocoder();
}
}
function showAddress(address) {
if (geocoder) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
alert(address + " not found");
} else {
map.setCenter(point, 13);
var marker = new GMarker(point);
map.addOverlay(marker);
marker.openInfoWindowHtml(address);
}
}
);
}
}
');
?>
However this is adding the maps API in twice with a lot of escaped html, which is causing the maps to fail to load. e.g.
然而,这是使用大量转义的html两次添加地图API,这导致地图无法加载。例如
<script type="text/javascript" src="<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=true&amp;key=ABQIAAAAHSJ3TgOTyvA1VzwU8g4Y7RT2yXp_ZAY8_ufC3CFXhHIE1NvwkxRmCy1h3nGv3n46kcqaFljsimqfWw" type="text/javascript"></script>"></script>
<script type="text/javascript" src="http://maps.google.com/maps?file=api&;v=2&;sensor=true&;key=ABQIAAAAHSJ3TgOTyvA1VzwU8g4Y7RT2yXp_ZAY8_ufC3CFXhHIE1NvwkxRmCy1h3nGv3n46kcqaFljsimqfWw"></script>
<script type="text/javascript">
//<!--
var map = null;
var geocoder = null;
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
map.setCenter(new GLatLng(37.4419, -122.1419), 13);
geocoder = new GClientGeocoder();
}
}
.....
Any idea why the google maps API is being added twice with the escaped html tags? I have no idea and the examples I have found don't seem to have this issue.
知道为什么谷歌地图API被添加两次与转义的HTML标签?我不知道,我发现的例子似乎没有这个问题。
Thanks in advance
提前致谢
1 个解决方案
#1
The reason you're not seeing any map is because the URL in your appendFile()
call is broken. Remove all the semi-colons:
您没有看到任何地图的原因是因为您的appendFile()调用中的URL已损坏。删除所有分号:
http://maps.google.com/maps?file=api&v=2&sensor=true&key=whatever
That will fix the second <script>
tag and make the Google map actually work.
这将修复第二个
That still leaves you with the first <script>
tag, though. But that must be related to how you're actually printing the contents of the HeadScript view helper. Can you show us what that code looks like?
但是,这仍然会留下第一个
#1
The reason you're not seeing any map is because the URL in your appendFile()
call is broken. Remove all the semi-colons:
您没有看到任何地图的原因是因为您的appendFile()调用中的URL已损坏。删除所有分号:
http://maps.google.com/maps?file=api&v=2&sensor=true&key=whatever
That will fix the second <script>
tag and make the Google map actually work.
这将修复第二个
That still leaves you with the first <script>
tag, though. But that must be related to how you're actually printing the contents of the HeadScript view helper. Can you show us what that code looks like?
但是,这仍然会留下第一个