Delphi 2009 应用程序中的 Google 地图
在这个项目中,我的目标是在 Delphi 2009 中通过 GoogleMaps 创建一个软件,它就像这个 但以不同的方式。在这个项目中,用户可以在地图上添加一个点,在图标旁边的每个点我都会添加一些信息,这些信息应该与图标相关,所以如果用户想单击其中一个点,信息将自动打开。我的问题是我可以创建信息,但是当我关闭它时我无法再次打开它。我该如何解决这个问题我的代码如下,非常感谢。
procedure TfrmMain.btnAddMarkerClick(Sender: TObject);
var
Doc2: IHTMLDocument2;
Win2: IHTMLWindow2;
latlng: String;
information: String;
begin
Doc2 := WebBrowser1.Document as IHTMLDocument2;
Win2 := Doc2.parentWindow;
information:='its a example';
latlng := '"' + leLat.Text + '", "' + leLng.Text + '"';
Win2.execScript('map.addOverlay(new GMarker(new GLatLng(' + latlng + ')) );', 'JavaScript');
Win2.execScript('map.openInfoWindow(new GLatLng(' + latlng + '),document.createTextNode("'+information +'"));','JavaScript');
end;
设计如下: 替代文本 http://img829.imageshack.us/img829/8474/adszdi.png< /a>
In this project my aim is to create a software via GoogleMaps in Delphi 2009, it will be like this one but in different way. In this project the user can add a point on the map and in every point beside the icon I will add some information and these information should be relate with the icon, so if the user want to click on one of them the information will open automatically. My problem is I can create the information but when I close it I can not open it again. How can I manage this problem my code as below, Thanks a lot.
procedure TfrmMain.btnAddMarkerClick(Sender: TObject);
var
Doc2: IHTMLDocument2;
Win2: IHTMLWindow2;
latlng: String;
information: String;
begin
Doc2 := WebBrowser1.Document as IHTMLDocument2;
Win2 := Doc2.parentWindow;
information:='its a example';
latlng := '"' + leLat.Text + '", "' + leLng.Text + '"';
Win2.execScript('map.addOverlay(new GMarker(new GLatLng(' + latlng + ')) );', 'JavaScript');
Win2.execScript('map.openInfoWindow(new GLatLng(' + latlng + '),document.createTextNode("'+information +'"));','JavaScript');
end;
The Design as below:
alt text http://img829.imageshack.us/img829/8474/adszdi.png
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
@asilloo,Google 地图 API 不会保存您的标记,此信息仅在浏览器的当前会话中有效,如果您需要保留(存储)标记,您必须手动执行此操作,您可以使用数据库或xml 文件。我建议您使用
KML
此任务的格式。@asilloo, The Google maps API does not save your markers, this information is valid only in the current session of your browser, if do you need persist (store) the markers you must do it yourself manually, you can use a database or an xml file. i recomend do you use the
KML
format for this task.我通过在 Delphi 中嵌入 Flash OCX 控件,使用 Google Maps Flex (Flash) API 创建了解决方案。对我来说它要快得多,并且我能够传递/检索复杂的参数。
也许你可以尝试一下:
http://www.delphiflash.com/
i created solution with the Google Maps Flex (Flash) API by embedding the Flash OCX Control in Delphi. For me its much faster and i'm able to pass/retrieve complex parameters.
maybe you give it a try:
http://www.delphiflash.com/
您的代码中的问题是您没有保存对信息窗口的任何引用。显示了信息窗口,实际上,当您关闭它时,它就消失了。
如果我正确理解您想要什么,您应该将事件处理程序添加到您创建的标记中。
您应该这样做:
代码:(
抱歉,如果这里有一些语法错误。我已经在 stackoverflow 上的这个蹩脚文本框中编辑了它)
让我知道它是否有效...
The problem in your code is that you don't save any reference to the infowindow. The infowindow is shown, and indeed, when you close it, it's gone.
If I understand what you want correctly, you should add an eventhandler to the markers that you create.
You should do it like this:
Code:
(sorry if there are some syntax errors here.. I've edited it in this crappy textbox on stackoverflow)
Let me know if it works...