WebBrowser not assigned

I am using Delphi Xe4 with google maps library. I created a sample application which the customers address on dbgrid.

On dbgrid event I did

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;

But when I do a double click it shows me the message : webbrowser not assinged.

How Can I solve this ?

Best Anderson


Before adding items to the map via GMMarker1, you need to be sure that the Geocoder returns valid coordinates. Once you have valid coordinates, the GMMarker1 component expects that you add a marker using the latitude and longitude from the Geocoder. Try this:

   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;

I changed the dbgrid double click to:

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; 

and it worked.

Now, when I click on any line on dbgrid shows on google map inside the webbrowser.

链接地址: http://www.djcxy.com/p/35090.html

上一篇: 多线程Socket服务器Java,连接重置SocketException

下一篇: WebBrowser未分配