0

this is my problem. From rails I call a function:

<body onload="initialize(<%= @segnalazione.id %>,<%= @segnalazione.dove %>); ">

where @segnalazione.dove is like "(lat, lng)".

On the called function, the map is not loaded because half cood is loaded. If I run "alert(coord);" I get only "lng". Why?

function initialize(id,coord) {
        var myOptions = {
            zoom: 11,
            center: coord,mapTypeId:google.maps.MapTypeId.ROADMAP,draggableCursor:'pointer'
            }
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
0

2 Answers 2

1

The first step to debugging a problem like this is to see what the code that Rails is generating looks like, i.e. what HTML/JavaScript is actually being sent to the browser.

In this case I'm guessing the problem is you're not quoting strings. Your first line should probably look like this:

<body onload="initialize(<%= @segnalazione.id %>, '<%= @segnalazione.dove %>'); ">

(Note the new single-quotes around the @segnalazione.dove ERb tag. This is necessary if @segnalazione.dove is a string instead of, say, an integer or other JavaScript literal.

Sign up to request clarification or add additional context in comments.

Comments

0

The problem is on <body onload="initialize(<%= @segnalazione.id %>,<%= @segnalazione.dove %>); "> if @segnalazione.dove expands to (lat, lng) the comma operator inside the parentheses will make (lat, lng) evaluate to lng. You can't use "()" how you seen to use it, go for {lat: lat, lng: lng}(as an object) or [lat, lng](as a array).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.