javascript - focusing on google maps api according to latitude and longitude -
i got code of drawing polylines in google maps here want focus on map according latitude , longitude, added line -> map.setcenter(new google.maps.latlng(-122.5868225097656,45.56117947133065)); polyline didn't appear because latitude , longitude outside screen , line added (map.setcenter) didn't change here code:
<!doctype html> <html> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no"> <meta charset="utf-8"> <title>simple polylines</title> <style> html, body, #map-canvas { height: 100%; margin: 0px; padding: 0px } </style> <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true"></script> <script> function initialize() { var mapoptions = { zoom: 3, center: new google.maps.latlng(0, -180), maptypeid: google.maps.maptypeid.terrain }; var map = new google.maps.map(document.getelementbyid('map-canvas'), mapoptions); map.setcenter(new google.maps.latlng(-122.5868225097656,45.56117947133065)); var flightplancoordinates = [ new google.maps.latlng(-122.5868225097656,45.56117947133065), new google.maps.latlng(-122.6348876953125,45.493833740092185) ]; var flightpath = new google.maps.polyline({ path: flightplancoordinates, geodesic: true, strokecolor: '#ff0000', strokeopacity: 1.0, strokeweight: 2 }); flightpath.setmap(map); } google.maps.event.adddomlistener(window, 'load', initialize); </script> </head> <body> <div id="map-canvas"></div> </body> </html>
-122.5868225097656,45.56117947133065 -122.6348876953125,45.493833740092185
are invalid latlong(s). reason why app not working right.
i tried interchange values. , working fine.
map.setcenter(new google.maps.latlng(45.56117947133065,-122.5868225097656)); var flightplancoordinates = [ new google.maps.latlng(45.56117947133065,-122.5868225097656), new google.maps.latlng(45.493833740092185,-122.6348876953125) ];