Jump to content

Latitude e Longitude


andersonrsbezerra

Recommended Posts

  • 5 years later...

I've used the following on mobile in response to a Button click on a simple dialog form named InputBox which has a TunimEdit control named InputEdit. You should be able to figure it out from the code snippets below:

procedure TInputBox.GeoButtonClick(Sender: TObject);

var
  GetLatLong : string;
begin
  UniSession.AddJS('InputBox.OKButton.showMask("Locating...");');
  GetLatLong := 'if (navigator.geolocation) {'+
                '      navigator.geolocation.getCurrentPosition(showPosition); '+
                '  } else {                                                     '+
                '      alert("Geolocation is not supported by this browser."); '+
                '      InputBox.OKButton.hideMask(); '+
                '  }  '+
                '  function showPosition(position) { ';

  if (pos(' LATITUDE ',Uppercase(Caption))>0) then
    GetLatLong := GetLatLong + '    ajaxRequest(InputBox.InputEdit,"Latitude",["Latitude="+position.coords.latitude+""]); }'
  else 
     GetLatLong := GetLatLong + '    ajaxRequest(InputBox.InputEdit,"Longitude",["Longitude="+position.coords.longitude+""]); }';
              
  UniSession.AddJS(GetLatLong);

end;

 

procedure TInputBox.InputEditAjaxEvent(Sender: TComponent; EventName: string;
  Params: TUniStrings);
var
  Key : word;
  Latitude,Longitude : string;
begin
  if (EventName='keypress') then
    begin
      Key := StrToInt(Params.Values['key']);
      if ord(Key)=13 then //Enter-key pressed
        begin
          FCallBack(trim(InputEdit.Text));
          Close;
        end;
    end
  else
  if EventName='Latitude' then
    begin
      Latitude := Params.Values['Latitude'];
      //ShowMessage('Latitude: '+Latitude);
      InputEdit.Text := Latitude;
      UniSession.AddJS('InputBox.OKButton.hideMask();');
    end
   else
  if EventName='Longitude' then
    begin
      Longitude := Params.Values['Longitude'];
      //ShowMessage('Latitude: '+Latitude);
      InputEdit.Text := Longitude;
      UniSession.AddJS('InputBox.OKButton.hideMask();');
    end
end;

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...