-3

I am using Delphi XE4 with a Google Maps library. I created a sample application which the customers address on dbgrid.

On the 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 assigned.

How can I solve this?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Anderson Muniz
  • 33
  • 1
  • 1
  • 7

2 Answers2

0

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;
John Easley
  • 1,551
  • 1
  • 13
  • 23
  • I changed the code according yours and when I executed the application returns the errors Javascript message "DoMap is undefined", I clicked on Yes to continue, returns an error message "Could not complete the operation due error 80020101" . – Anderson Muniz Jan 16 '17 at 16:42
  • I followed the links http://stackoverflow.com/questions/26467638/gmlib-google-maps-infowindow-error and http://stackoverflow.com/questions/37175704/gmlib-could-not-complete-the-operation-due-to-error-80020101-v1-5-3 and application works. Now when I opens the click on a address show on maps but it seems that the map is refreshing 1 ms. How can I change this and to changed only if is clicked ? – Anderson Muniz Jan 16 '17 at 18:30
  • You should update your question to include all of your current code, then maybe I can help. – John Easley Jan 16 '17 at 18:49
  • @AndersonMuniz it appears my answer helped you as it seems you used most if not all of my code.. unfair that you checked approved your own answer.. that's not how StackOverflow works. – John Easley Jan 18 '17 at 00:43
  • sorry I am new to stackoverflow. I didn't mean it. – Anderson Muniz Jan 18 '17 at 19:25
  • @AndersonMuniz no worries, welcome to Stack Overflow! – John Easley Jan 18 '17 at 19:55
-1

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 it shows on Google Maps inside the webbrowser.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Anderson Muniz
  • 33
  • 1
  • 1
  • 7