我正在尝试将 Google maps API V3 集成到我的 Rhodes (http://rhomobile.com/) 应用程序中。我在使用 Google Maps V3 创建桌面网站和 jQuery Mobile 网站时拥有良好的经验。但是,我就是无法让它工作。
我使用 iPhone 模拟器进行测试。在下面的 JS 代码中,代码在 alert("Test3"); 之间崩溃。和警报(“Test4”);
我在 layout.erb 的 head 部分中以这种方式调用 Google Maps V3 API:
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script src="/public/js/application.js" type="text/javascript"></script>
application.js 中的 JS 代码(包含在 layout.erb 中):
function initialize() {
alert("Test");
var latlng = new google.maps.LatLng(-34.397, 150.644);
alert("Test2");
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
alert("Test3");
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
alert("Test4");
}
查看代码:
<div class="pageTitle">
<h1>Map Test</h1>
</div>
<div class="toolbar">
<div class="leftItem backButton">
<a href="<%= url_for :action => :index %>">Back</a>
</div>
</div>
<div class="content">
<div id="map_canvas" style="width: 100%; height: 100%; padding: 0;"></div>
</div>
控制器代码:
def view
WebView.execute_js("initialize();")
end
同样,代码在 alert("Test3"); 之后崩溃。我没有收到任何错误消息,rhodes 只是打开页面并显示 Test、Test2 和 Test3 的弹出窗口。
是否有关于如何在 Rhodes 中使用 Google Maps V3 的示例。一定有一个我在某处遗漏的怪癖。