• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

DELPHI中应用GoogleMap[转]

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

想在DELPHI中应用GoogleMap吗,简单,费话不多说照着弄一下就明白了。
代码:
unit fMain;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, OleCtrls, SHDocVw, StdCtrls,
  ComCtrls, IdTCPConnection, IdTCPClient, IdHTTP, IdURI, ExtCtrls, IdBaseComponent, IdComponent;
type
  TfrmMain = class(TForm)
    WebBrowser1: TWebBrowser;
    btnAddMarker: TButton;
    StatusBar1: TStatusBar;
    btnGeocode: TButton;
    IdHTTP1: TIdHTTP;
    leLat: TLabeledEdit;
    leLng: TLabeledEdit;
    mmGeocode: TMemo;
    btnCenterMap: TButton;
    rbAPI: TRadioButton;
    rbCheat: TRadioButton;
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure btnAddMarkerClick(Sender: TObject);
    procedure btnCenterMapClick(Sender: TObject);
    procedure btnGeocodeClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
    procedure geocode(const s: String; out lat, lng: String);
    procedure geocodeCheat(const s: String; out lat, lng: String);
  public
    { Public declarations }
  end;
var
  frmMain: TfrmMain;
implementation
uses
   MSHTML, StrUtils, ActiveX;
const
   GOOGLE_MAPS_API_KEY = 'ABQIAAAAvrcNJEwrVo4hA_8eyQbk5BRuDRFc5_CuEQVEx-1xcZw7XTzD5hSiKWzRiiKVCLnPDSEF5x9j0zEK_g';
{$R *.dfm}
const
   rootDoc: String =
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"'
             +'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'#13
             +'<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">'#13
             +'<head>'#13
             +'<meta http-equiv="content-type" content="text/html; charset=utf-8"/>'#13
             +'<title>Google Maps JavaScript API Example: Simple Map</title>'#13
             +'<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key="'#13
             +'type="text/javascript"></script>'#13
             +'<script type="text/javascript">'#13
             +'var map;'
             +'function initialize() {'#13
             +'if (GBrowserIsCompatible()) {'#13
             +'map = new GMap2(document.getElementById("map_canvas"));'#13
             +'map.addControl(new GLargeMapControl());'#13
             +'map.addControl(new GMapTypeControl());'#13
             +'map.addControl(new GScaleControl());'#13
             +'map.addControl(new GOverviewMapControl());'#13
             +'map.setCenter(new GLatLng(31.573636,107.112648, 12, G_NORMAL_MAP));'#13
             +'map.enableContinuousZoom();'
             +'map.enableScrollWheelZoom();'
             +'  }'#13
             +' };'#13
             +'function createMarker(point, number) {'#13
             +'  var marker = new GMarker(point);'#13
             +'  var message = ["这","是","个","秘密","消息"];'#13
             +'marker.value = number;'#13
             +'  GEvent.addListener(marker, "click", function() {'#13
             +'    var myHtml = "<b>#" + number + "</b><br/>" + message[number -1];'#13
             +'    map.openInfoWindowHtml(point, myHtml);'#13
             +'   });'#13
             +'  return marker;'#13
             +'}'#13
             +'function showrandommarker(count){'
             +'var bounds = map.getBounds();'
             +'var southWest = bounds.getSouthWest();'
             +'var northEast = bounds.getNorthEast();'
             +'var lngSpan = northEast.lng() - southWest.lng();'
             +'var latSpan = northEast.lat() - southWest.lat();'
             +'for (var i = 0; i < count; i++) {'
             +'  var point = new GLatLng(southWest.lat() + latSpan * Math.random(), southWest.lng() + lngSpan * Math.random());'
             +'  map.addOverlay(createMarker(point, i + 1));'
             +'}}'
             +'function addployline(){'
             +'  var polyline = new GPolyline([new GLatLng(39.907,116.387), new GLatLng(39.935,126.407), new GLatLng(49.935,126.407)], "#ff0000", 3);'
            +'  map.addOverlay(polyline);'
             +'}'
             +'</script>'#13
             +'</head>'#13
             +'<body onload="initialize()" onunload="GUnload()">'#13
             +'<div way to do it'
    Anchors = [akTop, akRight]
    Caption = 'API'
    Checked = True
    ParentShowHint = False
    ShowHint = True
    TabOrder = 2
    TabStop = True
  end
  object rbCheat: TRadioButton
    Left = 680
    Top = 88
    Width = 49
    Height = 17
    Hint = 'Seems to be more accurate'
    Anchors = [akTop, akRight]
    Caption = 'Cheat'
    ParentShowHint = False
    ShowHint = True
    TabOrder = 3
  end
  object Button1: TButton
    Left = 624
    Top = 296
    Width = 125
    Height = 25
    Anchors = [akTop, akRight]
    Caption = 'AddPloyLine'
    TabOrder = 10
    OnClick = Button1Click
  end
  object IdHTTP1: TIdHTTP
    AllowCookies = True
    ProxyParams.BasicAuthentication = False
    ProxyParams.ProxyPort = 0
    Request.ContentLength = -1
    Request.Accept = 'text/html, */*'
    Request.BasicAuthentication = False
    Request.UserAgent = 'Mozilla/3.0 (compatible; Indy Library)'
    HTTPOptions = [hoForceEncodeParams]
    Left = 704
    Top = 400
  end
end
试用运行一下,一般没问题,有问题的话就要加入Google Map Key了,网上这方面介绍的有很多的。
说一下原理:在html中声明了一个 var map;是一个全局的对象,下面的几个方法都是对这个对象进行操作,俺JaveScript不太熟,只能随便写几句,能阐明意思,那就不错了。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
matlab 矩阵变换发布时间:2022-07-18
下一篇:
Delphi2010怎样获取程序内部自身版本?发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap