我正在研究在Google地圖上顯示某個點的代碼,並從一點到另一點製作線條。如代碼中所示,我應該輸入用戶位置,然後將用戶與其他Web服務位置連接。如何通過使用javascript讀取文件並在第
我的問題是我怎麼能讀取文本文件有經度和緯度的任何用戶,並顯示他們在地圖上,而不是手動輸入。
For example the file has data like this:
longitude latitude webS1 webS2 webS3
40.44390000000001 -79.9562 45 12 78
37.79499999999999 -122.2193 78 69 45
36.0 138.0 42 89 75
52.19999999999999 0.1167869 38 74 65
我需要的是這樣這樣的:
Enter user index:-----
插入的用戶,我們可以用經度和緯度該用戶的顯示在地圖上的位置索引之後。同時顯示webS的值。
例
Enter user index:1
的結果應該顯示在地圖上的位置,並顯示網的值在頁面上這樣
webS1=45
webS2=12
webs3=78
我是一個新的Java腳本和HTML編碼。誰可以給我任何關於做這種風格的建議。
這是我工作的代碼: ----------------------------------- <% - 文件:索引 創建於:2013年4月5日,下午8點59分13秒 著者:Bobaker - %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html >
<head>
<title>Show Google Map with Latitude and Longitude </title>
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyC6v5-2uaq_wusHDktM9ILcqIrlPtnZgEk&sensor=false">
</script>
<script type="text/javascript">
function initialize() {
var lat = document.getElementById('txtlat').value;
var lon = document.getElementById('txtlon').value;
var myLatlng = new google.maps.LatLng(lat, lon) // This is used to center the map to show our markers
var mapOptions = {
center: myLatlng,
zoom: 6,
mapTypeId: google.maps.MapTypeId.ROADMAP,
marker: true
};
var map = new google.maps.Map(document.getElementById("mapcanvas"), mapOptions);
<!-- --!>
var userPosition=new google.maps.LatLng(lat,lon);
var WebServicePosition1=new google.maps.LatLng(43,-98);
var WebServicePosition2=new google.maps.LatLng(58,93);
var WebServicePosition3=new google.maps.LatLng(-16,26);
var myTrip1=[userPosition,WebServicePosition1];
var myTrip2=[userPosition,WebServicePosition2];
var myTrip3=[userPosition,WebServicePosition3];
var flightPath1=new google.maps.Polyline({
path:myTrip1,
strokeColor:"#00000F",
strokeOpacity:0.9,
strokeWeight:3
});
var flightPath2=new google.maps.Polyline({
path:myTrip2,
strokeColor:"#ff0000",
strokeOpacity:0.9,
strokeWeight:3
});
var flightPath3=new google.maps.Polyline({
path:myTrip3,
strokeColor:"#0000FF",
strokeOpacity:0.9,
strokeWeight:3
});
flightPath1.setMap(map);
flightPath2.setMap(map);
flightPath3.setMap(map);
var marker = new google.maps.Marker({
position: myLatlng
});
marker.setMap(map);
}
</script>
</head>
<body >
<form id="form1" runat="server">
<table >
<tr>
<td>Enter Latitude:</td>
<td><input type="text" id="txtlat" value="40.44390000000001" /> </td>
</tr>
<tr>
<td>Enter Longitude:</td>
<td><input type="text" id="txtlon" value="-79.9562" /> </td>
</tr>
<tr>
<td></td>
<td><input type="button" value="Submit" onclick="javascript:initialize()" /> </td>
</tr>
</table>
<div id="mapcanvas" style="width: 500px; height: 400px">
</div>
</form>
</body>
</html>
預先感謝
你可以把你的建議在代碼中,我會測試它。因爲我不熟悉AJAX和JSON – 2013-04-10 13:56:26
請參閱我的答案的編輯。 – 2013-04-11 06:03:49
感謝您所做的一切,我用另一個想法部分解決了我的問題。所以我使用switch-case,但是我需要的是讀取表單文件中有300個用戶的數據,如果我將它們一個一個地存儲在switch-case中,那是很乏味的。謝謝你的努力。 – 2013-04-23 15:38:35