-- 作者:baoxyang
-- 发布时间:2014/7/13 14:57:00
-- 求助获取网页数据
<html> <head> <meta http-equiv="Content-Type" c /> <style type="text/css"> body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;} </style> <script type="text/javascript" src="http://api.map.baidu.com/api?v=1.4"></script> <title>根据起终点经纬度驾车导航</title> </head> <body> <div id="allmap"></div> <input type="hidden" id="jcgl_value" value="" /> </body> </html> <script type="text/javascript"> var jcgl_value = document.getElementById("jcgl_value"); var map = new BMap.Map("allmap"); map.centerAndZoom(new BMap.Point(121.391303, 31.248187), 15); var p1 = new BMap.Point(121.391303,31.248187); var p2 = new BMap.Point(121.291771,31.261807); function getCJState (){ var searchComplete = function (results){ if (transit.getStatus() != BMAP_STATUS_SUCCESS){ jcsj_value.value = 0; jcgl_value.value = 0; return ; } var plan = results.getPlan(0); jcgl_value.value = plan.getDistance(true); }
var transit = new BMap.TransitRoute(map, {renderOptions: {map: map}, onSearchComplete: searchComplete, onPolylinesSet: function(){ setTimeout(function(){alert(jcgl_value.value)},"1000"); }}); transit.search(p1, p2); } </script>
但在狐表调用e.Form.controls("textbox33").value = tdom.GetElementById("jcgl_value").GetAttribute("value")获取的数据总是第二次数据,请教这个如何解决
Dim x1,x As String Dim y1,y As String Dim p1 As String = e.sender.value Dim p As String = "上海市金华路898号" If p1 = "" Or p = "" Then e.Form.controls("textbox33").value = 0 & "公里" Else Dim XMLH1 As Object XMLH1 = CreateObject("Microsoft.XMLHTTP") XMLH1.open("GET", "http://api.map.baidu.com/geocoder?output=json&address=" & p1, True) XMLH1.send(Nothing) Do While XMLH1.readyState <> 4 Application.DoEvents Loop Dim json1 As String = XMLH1.responseText Dim ScriptControl1 As Object, data1 As Object, JscriptCode1 As String JscriptCode1 = "function toObject(json) {eval(""var o=""+json);return o;}" ScriptControl1 = CreateObject("MSScriptControl.ScriptControl") With ScriptControl1 .Language = "Javascript" .Timeout = -1 .AddCode(JscriptCode1) data1 = .Run("toObject", json1) End With \'设置htm地图的显示坐标 Try x1 = data1.result.location.lng y1 = data1.result.location.lat Catch ex As Exception x1 = 0 y1 = 0 End Try Dim XMLH As Object XMLH = CreateObject("Microsoft.XMLHTTP") XMLH.open("GET", "http://api.map.baidu.com/geocoder?output=json&address=" & p, True) XMLH.send(Nothing) Do While XMLH.readyState <> 4 Application.DoEvents Loop Dim json As String = XMLH.responseText Dim ScriptControl As Object, data As Object, JscriptCode As String JscriptCode = "function toObject(json) {eval(""var o=""+json);return o;}" ScriptControl = CreateObject("MSScriptControl.ScriptControl") With ScriptControl .Language = "Javascript" .Timeout = -1 .AddCode(JscriptCode) data = .Run("toObject", json) End With \'设置htm地图的显示坐标 Try x = data.result.location.lng y = data.result.location.lat Catch ex As Exception x = 0 y = 0 End Try If x = 0 Or y =0 Or x1=0 Or y1 = 0 Then e.Form.controls("textbox33").value = 0 & "公里" Else Dim data2 As String = FileSys.ReadAllText(ProjectPath & "map4") data2 = data2.Replace("/*经度*/", x1).Replace("/*纬度*/", y1).Replace("/*等级*/",15).Replace("/*px1*/", x1).Replace("/*py1*/", y1).Replace("/*px2*/", x).Replace("/*py2*/", y) FileSys.WriteAllText(ProjectPath & "map4.htm", data2, False) e.Form.Controls("WebBrowser1").Address = ProjectPath & "map4.htm" Dim tdom As System.Windows.Forms.HTMLDocument = e.Form.Controls("WebBrowser1").BaseControl.Document Do While tdom Is Nothing OrElse tdom.GetElementById("jcgl_value").GetAttribute("value") Is Nothing \' Do While e.Form.Controls("WebBrowser1").BaseControl.ReadyState <> 4 Application.DoEvents Loop e.Form.controls("textbox33").value = tdom.GetElementById("jcgl_value").GetAttribute("value")这,总是获取是数据是第二次数据,请教这个如何解决 End If End If
|