This is incorrect: new google.maps.LatLng(coordsArray[i].location)
.
You state: "location been database field returning LatLng -43.59670,172.38247 as a string."
the google.maps.LatLng constructor takes two numbers as arguments (not a comma separated string).
If coordsArray[i].location
is a comma separated string, convert it to two numbers.
var coords = coordsArray[i].location.split(",");
var latLng = new google.maps.LatLng(parseFloat(coords[0]), parseFloat(coords[1]));
var marker = new google.maps.Marker({
position: latLng,
map: map
});
code snippet:
var geocoder;
var map;
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 location = "-43.59670,172.38247";
coords = location.split(",");
var latLng = new google.maps.LatLng(parseFloat(coords[0]), parseFloat(coords[1]));
var marker = new google.maps.Marker({
position: latLng,
map: map
});
map.setCenter(latLng);
}
google.maps.event.addDomListener(window, "load", initialize);
html,
body,
#map_canvas {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js?"></script>
<div id="map_canvas"></div>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…