我得到了位置(lat和long),但是位置不正确,小数点不正确。因此,我被告知使用以下代码进行转换:
var location = "N1433.704483,E12100.012501";
var latlngarr = location[1].split(",");
if (latlngarr) {
longitude = latlngarr[1]; //经度
if (longitude.indexOf("E") >= 0) {
longitude = longitude.substring(1);
var degree = longitude / 100 | 0; //除100后取整。
var cent = (longitude - degree * 100); //分的部分。
longitude = degree + cent / 60.0;
} else if (longitude.indexOf("W") >= 0) {
longitude = longitude.substring(1);
var degree = longitude / 100 | 0; //除100后取整。
var cent = (longitude - degree * 100); //分的部分。
longitude = degree + cent / 60.0;
}
latitude = latlngarr[0]; //纬度
if (latitude.indexOf("N") >= 0) {
latitude = latitude.substring(1);
var degree = latitude / 100 | 0; //除100后取整。
var cent = (latitude - degree * 100); //分的部分。
latitude = degree + cent / 60.0;
} else if (latitude.indexOf("S") >= 0) {
latitude = latitude.substring(1);
var degree = latitude / 100 | 0; //除100后取整。
var cent = (latitude - degree * 100); //分的部分。
latitude = degree + cent / 60.0;
}
}但是当我试图把它放在我的代码中时,页面上写着“对象没有找到!”这是我的完整密码。
var location = "N1433.704483,E12100.012501";
var latlngarr = location[1].split(",");
if (latlngarr) {
longitude = latlngarr[1]; //经度
if (longitude.indexOf("E") >= 0) {
longitude = longitude.substring(1);
var degree = longitude / 100 | 0; //除100后取整。
var cent = (longitude - degree * 100); //分的部分。
longitude = degree + cent / 60.0;
} else if (longitude.indexOf("W") >= 0) {
longitude = longitude.substring(1);
var degree = longitude / 100 | 0; //除100后取整。
var cent = (longitude - degree * 100); //分的部分。
longitude = degree + cent / 60.0;
}
latitude = latlngarr[0]; //纬度
if (latitude.indexOf("N") >= 0) {
latitude = latitude.substring(1);
var degree = latitude / 100 | 0; //除100后取整。
var cent = (latitude - degree * 100); //分的部分。
latitude = degree + cent / 60.0;
} else if (latitude.indexOf("S") >= 0) {
latitude = latitude.substring(1);
var degree = latitude / 100 | 0; //除100后取整。
var cent = (latitude - degree * 100); //分的部分。
latitude = degree + cent / 60.0;
}
}
var locations = [
['Bondi Beach', latitude, longitude],
];
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: new google.maps.LatLng(14.5833, 120.9667),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map
});
google.maps.event.addListener(marker, 'click', (function (marker, i) {
return function () {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}有人能告诉我我的密码出了什么问题吗?
发布于 2014-02-27 06:46:03
位置不是数组,而是字符串,因此location1没有意义。"location“是变量的坏名称,它会在某些浏览器中更改页面的URL。
var location = "N1433.704483,E12100.012501";
var latlngarr = location[1].split(",");应:
var plocation = "N1433.704483,E12100.012501";
var latlngarr = plocation.split(",");https://stackoverflow.com/questions/22060308
复制相似问题