我正在使用带有Google地图库的Delphi XE4。我创建了一个客户在dbgrid上解决的示例应用程序。
在我做过的dbgrid事件上:
procedure TForm1.DBGrid1DblClick(Sender: TObject);
var
endereco : string;
pesquisarendereco : string;
begin
WebBrowser1.Enabled := True;
GMMap1.Active := True;
if dsClienteEndereco.DataSet.RecordCount > 0 then
begin
GMGeoCode1.Geocode(qryClienteEndereco.FieldByName('ENDERECORESIDENCIA').AsString);
endereco := qryClienteEnderecoENDERECORESIDENCIA.Value;
GMMarker1.Items[dsClienteEndereco.DataSet.Recno].CenterMapToMarker;
pesquisarendereco := 'http://maps.google.com/maps?q=' + endereco;
WebBrowser1.Navigate(pesquisarendereco);
end;
end;
但是,当我双击时,它会显示消息:
webbrowser未分配。
我该如何解决这个问题?
答案 0 :(得分:0)
在通过GMMarker1将项目添加到地图之前,您需要确保Geocoder返回有效坐标。获得有效坐标后,GMMarker1组件需要使用Geocoder中的纬度和经度添加标记。试试这个:
WebBrowser1.Enabled := True;
GMMarker1.Map := GMMap1;
GMMap1.WebBrower := WebBrowser1;
GMMap1.Active := True;
if dsClienteEndereco.DataSet.RecordCount > 0 then
begin
GMGeoCode1.Geocode(qryClienteEndereco.FieldByName('ENDERECORESIDENCIA').AsString);
If GmGeoCode1.Count <> 0 then
begin
endereco := qryClienteEnderecoENDERECORESIDENCIA.Value;
GMMarker1.Add(GmGeoCode1[0].Geometry.Location.Lat, GmGeoCode1[0].Geometry.Location.Lng, endereco);
GMMarker1.items[GMMarker1.Count-1].CenterMapToMarker;
// you shouldn't need these lines, the WebBrowser should navigate on its own
//pesquisarendereco:='http://maps.google.com/maps?q='+endereco;
//WebBrowser1.Navigate(pesquisarendereco);
end;
end;
答案 1 :(得分:-1)
我将dbgrid双击更改为:
procedure TformHistoricoRotas.DBGrid1DblClick(Sender: TObject);
var
endereco: string;
pesquisarendereco: string;
Marker: TMarker;
begin
WebBrowser1.Enabled := True;
GMMarker1.Map := GMMap1;
GMMap1.WebBrowser := WebBrowser1;
GMMap1.Active := True;
if dsClienteEndereco.DataSet.RecordCount > 0 then
begin
GMGeoCode1.Geocode(qryClienteEndereco.FieldByName('ENDERECORESIDENCIA').AsString);
If GmGeoCode1.Count <> 0 then
begin
endereco := IntToStr(qryClienteEnderecoPRIORIDADE.Value) + ', ' + qryClienteEnderecoCHECKOUT.Value + ', ' + qryClienteEnderecoENDERECORESIDENCIA.Value;
GMMarker1.Add(GmGeoCode1[0].Geometry.Location.Lat, GmGeoCode1[0].Geometry.Location.Lng, endereco);
//GMMarker1.Add(GmGeoCode1[0].Geometry.Location.Lat, GmGeoCode1[0].Geometry.Location.Lng, endereco);
GMMarker1.items[GMMarker1.Count-1].CenterMapToMarker;
GMMap1.Precision := 30;
end;
end;
end;
并且有效。
现在,当我点击dbgrid上的任何一行时,它会显示在webbrowser内的Google地图上。