javascript - Changing Coordinate string into a float -
i have geo coordinate json file
{"location": "5.554565999999999,-0.2302829999999858"}
i know how can convert float before using in google map.
i glad if can me, thank you.
one way (there many):
var coords = json.location.split(','); var latlng = new google.maps.latlng(parsefloat(coords[0]), parsefloat(coords[1]));
code snippet:
var geocoder; var map; var json = { "location": "5.554565999999999,-0.2302829999999858" }; function initialize() { var map = new google.maps.map( document.getelementbyid("map_canvas"), { center: new google.maps.latlng(37.4419, -122.1419), zoom: 13, maptypeid: google.maps.maptypeid.roadmap }); var coords = json.location.split(','); var latlng = new google.maps.latlng(parsefloat(coords[0]), parsefloat(coords[1])); map.setcenter(latlng); var marker = new google.maps.marker({ position: latlng, map: map }); } google.maps.event.adddomlistener(window, "load", initialize);
html, body, #map_canvas { height: 500px; width: 500px; margin: 0px; padding: 0px }
<script src="https://maps.googleapis.com/maps/api/js"></script> <div id="map_canvas" style="width:750px; height:450px; border: 2px solid #3872ac;"></div>
Comments
Post a Comment