0

JAVASCRIPT

Im sure this a very simple problem.

I am modifying the line below and want to replace (53, 0) with a variable. However, the variable that is created called 'result', is equal to '(34, 2)', ie it already has the brackets around it.

center: new google.maps.LatLng.(53, 0)

i have tried

center: new google.maps.LatLng.(result)
center: new google.maps.LatLng.result
center: new google.maps.LatLng.({result})

and it no working!

FULL CODE

var geocoder = new google.maps.Geocoder();

  if (geocoder) {
     geocoder.geocode({ 'address': address }, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {

          window.result = results[0].geometry.location;

          alert(result);



        } 
        else {
          alert('nothing');
        }
     });
  }

  function load() {

    map = new google.maps.Map(document.getElementById("map"), {
    center: new google.maps.LatLng.(53, 0),
    zoom: 10,
    mapTypeId: 'roadmap',
    mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU}
  });

}

For reference, alert(result) returns

(53.8622017, -2.405405999999971)

3 Answers 3

2

you putting . after the LatLng the correct way to create the latlng object was try this way

center:new google.maps.LatLng(-34.397, 150.644);

here . define the package level and the last latLng was class

like google is top level in that maps and in that LatLng was defined.

So the LatLng has 2 parameter (latitude and longitude)

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

Comments

0

Try new google.maps.LatLng(result[0], result[1])? Please post where the 'result' variable is created.

Comments

0

why don't you set your map center in the response

if (status == google.maps.GeocoderStatus.OK) {

         map.setCenter(results[0].geometry.location);

  }

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.