1

I can successfully generate a google map with the code below:

var myLatlng = new google.maps.LatLng(37.77493, -122.419415);
var myOptions = {
    zoom: 15,
    center: myLatlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

However when I try to do it with the block of code below (storing the coordinate in a variable). The map comes up as all blue, with or with out the replace function.

var coordinate = "37.77493,-122.419415";
coordinate = coordinate.replace('"','');
var myLatlng = new google.maps.LatLng(coordinate);
var myOptions = {
    zoom: 15,
    center: myLatlng,
    mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

Can anyone tell me what's going wrong?

2
  • What are you trying to do? The google.maps.LatLng constructor takes two numbers (like your first example), not a string (like the code that doesn't work). Where do those two numbers come from? Commented May 10, 2013 at 21:43
  • Are you trying to do something like this? Commented May 10, 2013 at 21:47

1 Answer 1

3

It looks like LatLng constructor takes two numbers not a string

var coordinates = "37.77493,-122.419415".split(',');
var myLatlng = new google.maps.LatLng(coordinates[0], coordinates[1]);
Sign up to request clarification or add additional context in comments.

1 Comment

I edited code and solution is same with you :) Is this a joke :)

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.