I have a liitle problem when i try to change location. I`m connected to map
var mapOptions = {
zoom: 7,
center: new google.maps.LatLng(48.379433, 31.165579999999977),
mapTypeControl: false,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
And now I need to change location on the map
<select onChange="changeCity()" id="city"><option value="50.4501, 30.523400000000038">Київ</option><option value="49.839683, 24.029717000000005">Львів</option></select>
For that I`m using:
function changeCity() {
var city = document.getElementById('city').value;
var city_1 = new google.maps.LatLng(city);
map.setCenter(city_1);
}
But nothing happens (i see grey area). Please help…!
The problem is that
is not equivalent to
Your values in the
optiontags are specified as single string instances, like"50.4501, 30.523400000000038"for Kiev. Notice the double quotes.The
new LatLng()constructor would expect two numeric values. So you have to parse the value string into separate latitude and longitude values and pass them to thenew LatLng()constructor:Reference: