Home > Software engineering >  VC/MFC embedded Google Map
VC/MFC embedded Google Map

Time:10-17

use Active x controls CWebBrowser control implement MFC dialog box embedded Google map, the problems are as follows: Google - earth. HTML file via a browser can normal open, but not using HTML files in a vc + + program, according to have a friend encountered similar problems, to show just a little, appreciated, and the source file download address: http://download.csdn.net/detail/qq_22081879/9571229

The code is as follows:
vc + + program: (only in OnInitDialog () to add a few lines of code, to do the test)
 
//TODO: add additional initialization code in the
CHAR szPath [255].//path
Memset (szPath, 0, sizeof (char) * 255);//path reset
GetCurrentDirectory (255, szPath);//get the current directory
StrCat (szPath, \ \ "Google - earth. HTML");
M_webBrower. SetSilent (TRUE);//ban pop-up script errors
M_webBrower. Navigate (szPath, NULL, NULL, NULL, NULL);

HTML code (derived from the network) :
 & lt; ! PUBLIC DOCTYPE HTML "-///DTD/W3C XHTML 1.0 Strict//EN" 
"Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" & gt;

<meta HTTP - equiv="content-type" content="text/HTML. Charset=gb2312 "/& gt; Google maps JavaScript API example: map tag & lt;/title> <br/><script SRC="http://ditu.google.cn/maps? The file=api& amp; V=2 & amp; amp; Key=ABQIAAAAzr2EBOXUKnm_jVnk0OJI7xSosDVG8KKPE1 m51RBrvYughuyMxQ - i1QfUnH94QxWIa6N4U6MouMmBA & amp; Hl=useful - CN "type=" text/javascript "& gt; </script> <br/><br/><The script type="text/javascript" & gt; <br/>The function the initialize () <br/>{<br/>If (GBrowserIsCompatible ())//if the browser supports Google map <br/>{<br/>The map=new GMap2 (document. GetElementById (" map_canvas "));//define a map variables, without the var keyword that is a global variable <br/>Map. SetCenter (new GLatLng (22.536, 113.956), 14);//set the initial center and zoom level <br/>//map. OpenInfoWindow (map) getCenter (), the document. The createTextNode (" Hello, world "));//display a bubble <br/>Map. AddControl (new GLargeMapControl ());//increase large scale article <br/>//map. AddControl (new GSmallMapControl ());//add article small scale <br/>Map. AddControl (new GMapTypeControl ());//increase map type switch button <br/>Var point=new GLatLng (22.536, 113.956);//generates a coordinate point <br/>Map. AddOverlay (new GMarker (point));//add a map marker <br/>//GEvent. AddListener (map, "click", function () {alert (" click map "); });//register click event listener, set the response function <br/>} <br/>} <br/></script> <br/><The script type="text/javascript" & gt; <br/>The function jsfunctiontest () & lt; ! - this function will be VC code calls - & gt; <br/>{<br/>Alert (" this is alert function of JS "); <br/>//map. PanTo (new GLatLng (39.927, 116.407));//jump to the specified coordinates to the <br/>} <br/></script> <br/><The script type="text/javascript" & gt; <br/>The function TansTo (lat and LNG)//turn to the specified location, there are two parameters, latitude and longitude <br/>{<br/>//alert (LNG);//test parameters are passed <br/>//var longi=parseFloat (LNG);//afterwards just know, don't have to type conversion, javascript can automatically convert <br/>//var lati=parseFloat (lat); <br/>Map. PanTo (new GLatLng (lat and LNG)); <br/>} <br/></script> <br/></head> <br/><The body onl oad="the initialize ()" onunload="GUnload ()" & gt; <! -//page load after the completion of the execution the initialize () function - & gt; <br/><Div id="map_canvas" style="width: 800 px; Height: 500 px "& gt; </div> <! - define named map_canvas DIV - & gt; <br/></body> <br/></html> <br/></pre> <br/><br/><p class="article - content rp"> CodePudding user response: </p>Function of the webbrowser control support is not good enough, not as good as the browser<p class="article - content rp"> CodePudding user response: </p>Then how to do? I present the compiled operation can display the map page, but it shows not directly execute the executable file exe, prompt cancelled page navigation... </div> <div class="th_page th_page_color"></div> <div class="umCopyright"> <p>Page link:<a href="/Softwareengineering/67591.html" target="_blank" style="color:#999">https//www.codepudding.com/Softwareengineering/67591.html</a></p> </div> <div class="detail-arr"> <div class="detail-arr-left">Prev:<a href='/Softwareengineering/67590.html'>MyGraphCut</a></div> <div class="detail-arr-right">Next:<a href='/Softwareengineering/67592.html'>Visual studio2015 installation problem</a></div> </div> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="hot-tags neitags"> <ul> <li><i class="iconfont icon-x-tags"></i> Tags:  </li> <a href='/e/tags/?tagname=interface' target='_blank'>interface</a> </ul> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="xiangguan"> <ul class="msg msghead"> <li class="tbname">Related</li> </ul> <ul> </ul> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="flinks"> <ul> <li><i class="iconfont icon-x-tags"></i> Links:  </li> <li class="liflinks"><a target="_blank" href="/" title="CodePudding">CodePudding</a></li> </ul> </div> </div> </div> </div> <div class="footer"> <p><span style="font-size:16px;color:#666;font-weight: bold">About Us:</span>  <a href="https://www.codepudding.com/contact.html">Contact Us</a>      <a href="https://www.codepudding.com/service.html">Terms of Service</a>      <a href="https://www.codepudding.com/privacy.html"> Privacy Policy</a></p> <p class="foot_info">Copyright © 2010-2023,Powered By <a href="/" target="_blank">CodePudding</a> </p> </div> <script type="text/javascript" src="/skin/code/tianhu.js"></script> </body></html>