Google Maps Api V3 Problem

101 views
Skip to first unread message

Nick

unread,
Aug 18, 2011, 8:53:56 PM8/18/11
to rhomobile
Hi,

I'm trying to integrate Google maps API V3 into my Rhodes app. I have
good experience with Google Maps V3 as I created a desktop website and
a jQuery Mobile Website with it. However, I just can't get it to work.

I use the iPhone Simulator to test. In the JS code below, the code
crashes between the alert("Test3"); and alert("Test4");

I call the Google Maps V3 API this way in the head section of
layout.erb:
<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>

JS code in application.js (included in 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");
}

View code:

<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>

Controller code:

def view
WebView.execute_js("initialize();")
end

Again, the code crashes after the alert("Test3");. I don't get any
error messages, rhodes just open the page and shows a popup for Test,
Test2 and Test3.

Is there an example anywhere on how to use Google Maps V3 with Rhodes.
There gotta be a quirk I'm missing somewhere.

HorstPotter

unread,
Aug 19, 2011, 9:14:25 AM8/19/11
to rhomobile
Could you implement an 'alert(typeof google);' in initialize() plz?

If you get an 'undefined' its just not loaded somehow (no connection,
or your initialize method is called before
the api is loaded completely).

HorstPotter

unread,
Aug 19, 2011, 9:16:07 AM8/19/11
to rhomobile
I use it like this (jQuery-Style):

<script type="text/javascript">
$('#google-maps-index-page').live('pagecreate',function(event){
var map;
var myLatlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 8,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map($('#map_canvas')[0], myOptions);
});
</script>

Nick

unread,
Aug 22, 2011, 6:35:35 AM8/22/11
to rhomobile
Hi,

yes, now that Rhodes 3.1 is out and uses jQuery I can get Google maps
work just fine. Must be a problem with jQTouch. Anyways, it works now.
Thanks!

Amit Kumar Swami

unread,
Feb 3, 2014, 1:45:26 AM2/3/14
to rhom...@googlegroups.com
Hi Nick,

Did you get it working?? Can you please share this with me. As a newbie i am stuck with Map V3 in 
rhomobile. Nothing is appearing on Page.
Reply all
Reply to author
Forward
0 new messages