jahlxx Posted December 21, 2022 Share Posted December 21, 2022 Hi all. I have this function (is an example): function Tlib.GetGeoInfo2(const IpAddress: string): string; var get_url: string; lHTTP: TIdHTTP; sURL: string; xgeoloc: string; begin lHTTP := TIdHTTP.Create(nil); sURL := 'http://api.ipinfodb.com/v3/ip-city/?key=bf37c2d7fffa57c8a0dd1260bdfe5dcaf587b250562ea1f768b5cc4eb3f55b99&ip=188.85.82.223'; //get_url := Format(sURL, [IpAddress]); xgeoloc := ''; try xgeoloc := lHTTP.Get(sURL); finally lHTTP.free; end; GetGeoInfo2 := xgeoloc; end; In I run this, returns HTTP/1.1 403 Forbidden, but, If I copy the url, and paste directly in a browser, works perfect. Please, can someone give me some help? Thanks. Quote Link to comment Share on other sites More sharing options...
irigsoft Posted December 21, 2022 Share Posted December 21, 2022 48 minutes ago, jahlxx said: Hi all. I have this function (is an example): function Tlib.GetGeoInfo2(const IpAddress: string): string; var get_url: string; lHTTP: TIdHTTP; sURL: string; xgeoloc: string; begin lHTTP := TIdHTTP.Create(nil); sURL := 'http://api.ipinfodb.com/v3/ip-city/?key=bf37c2d7fffa57c8a0dd1260bdfe5dcaf587b250562ea1f768b5cc4eb3f55b99&ip=188.85.82.223'; //get_url := Format(sURL, [IpAddress]); xgeoloc := ''; try xgeoloc := lHTTP.Get(sURL); finally lHTTP.free; end; GetGeoInfo2 := xgeoloc; end; In I run this, returns HTTP/1.1 403 Forbidden, but, If I copy the url, and paste directly in a browser, works perfect. Please, can someone give me some help? Thanks. Hello, try to use https://, maybe securing of API is active by http ! https://api.ipinfodb.com/v3/ip-city/?key=bf37c2d7fffa57c8a0dd1260bdfe5dcaf587b250562ea1f768b5cc4eb3f55b99&ip=188.85.82.223 Quote Link to comment Share on other sites More sharing options...
Abaksoft Posted December 21, 2022 Share Posted December 21, 2022 25 minutes ago, irigsoft said: Hello, try to use https://, maybe securing of API is active by http ! https://api.ipinfodb.com/v3/ip-city/?key=bf37c2d7fffa57c8a0dd1260bdfe5dcaf587b250562ea1f768b5cc4eb3f55b99&ip=188.85.82.223 Humm... Also Not work Project Project1.exe raised exception class EIdOSSLUnderlyingCryptoError with message 'Error connecting with SSL. error:1409442E:SSL routines:SSL3_READ_BYTES:tlsv1 alert protocol version'. I tried all Indy Client IdHTTP1 parameters ... Quote Link to comment Share on other sites More sharing options...
Abaksoft Posted December 21, 2022 Share Posted December 21, 2022 1 hour ago, jahlxx said: Please, can someone give me some help? Thanks. Try Demo From : https://github.com/antoniojmsjr/IPGeoLocation Quote Link to comment Share on other sites More sharing options...
jahlxx Posted December 21, 2022 Author Share Posted December 21, 2022 Thanks. I'll try. But this used to work in the past. I don't know since when this doesn't works. Is very suspicious that typing the url in the browser works, but don't work from application. Quote Link to comment Share on other sites More sharing options...
jahlxx Posted December 22, 2022 Author Share Posted December 22, 2022 21 hours ago, Abaksoft said: Try Demo From : https://github.com/antoniojmsjr/IPGeoLocation Hi. This works perfect, thanks. The only problem is that the location is not OK. For example it give my location in other city near me. For the purpose I'm working, I need more accuracy. Is possible activate the GPS in the cell phone from a unigui mobile application? I need the exact location (or as near as possible) of the user for some operations. Some mobile applications, raise a message in the cell phone asking for activate the GPS, and if its not activated, the the option dosen't works. Is there any way to do this? Thanks. Quote Link to comment Share on other sites More sharing options...
irigsoft Posted December 22, 2022 Share Posted December 22, 2022 40 minutes ago, jahlxx said: Is possible activate the GPS in the cell phone from a unigui mobile application? I need the exact location (or as near as possible) of the user for some operations. Yes, You can use javascript for this and AddJS on uniGui: https://www.google.com/search?q=javascript+get+gps+location+android&oq=get+gps+javascript&aqs=chrome.1.69i57j0i22i30l3j0i390.5918j0j7&sourceid=chrome&ie=UTF-8 1. https://stackoverflow.com/questions/26461367/get-gps-location-using-javascript 2. https://gis.stackexchange.com/questions/41374/accessing-gps-data-with-javascript-in-real-time 3. GetGeoLocation.txt 4. using unigui + Android Device + webview (android App) Quote Link to comment Share on other sites More sharing options...
irigsoft Posted December 22, 2022 Share Posted December 22, 2022 Here is some try to enable GPS via javascript: //Enable GPS //Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE"); //intent.putExtra("enabled", true); //sendBroadcast(intent); if ("geolocation" in navigator) { /* geolocation is available */ var watchID = navigator.geolocation.watchPosition( function(position) { var out = document.getElementById ("out"); out.innerHTML = "lat:" + position.coords.latitude + ", long:" + position.coords.longitude //+ ",High: " + position.coords.accuracy ; } ); } else { /* geolocation IS NOT available */ alert ("geolocation IS NOT available"); } Quote Link to comment Share on other sites More sharing options...
jahlxx Posted December 22, 2022 Author Share Posted December 22, 2022 Ok friend. I'll test. Do you have a full example to help me? (in delphi) Thanks. Quote Link to comment Share on other sites More sharing options...
irigsoft Posted December 22, 2022 Share Posted December 22, 2022 1 hour ago, jahlxx said: Ok friend. I'll test. Do you have a full example to help me? (in delphi) Thanks. I don't have it like a testcase. I will explain how to use it. Option I with unigui and Javascript: 1. Create New uniGui project 2. use one TuniLabel with name: MyDataLabel 3. use UniTimer1Timer with : uniSession.addJS ( //Enable GPS //'Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");' //+ 'intent.putExtra("enabled", true);' //+ 'sendBroadcast(intent);' + 'if ("geolocation" in navigator) {' /* geolocation is available */ + ' var watchID = navigator.geolocation.watchPosition(' + ' function(position) {' + ' var out = document.getElementById ("' + MyDataLabel.JSId + '");' + ' out.innerHTML = "lat:" + position.coords.latitude ' + ' + ", long:" + position.coords.longitude' //+ ",High: " + position.coords.accuracy + ' ;' + ' }' + ');' + '} else {' /* geolocation IS NOT available */ + ' alert ("geolocation IS NOT available");' + '}' ); for this You must manually start GPS on mobile Device Option II unigui + Javascript + webView 1. Create New Android Project (with Android Studio like example) 2. Create uniGui app with same functionality like Option I 3. with installing AndroidApp you will ask user to enable GPS when app start: https://stackoverflow.com/questions/4721449/how-can-i-enable-or-disable-the-gps-programmatically-on-android https://www.google.com/search?q=android+enable+gps+programmatically&oq=android+enable+gps&aqs=chrome.1.69i57j0i512l2j0i22i30l7.5139j0j7&sourceid=chrome&ie=UTF-8 Quote Link to comment Share on other sites More sharing options...
jahlxx Posted December 22, 2022 Author Share Posted December 22, 2022 WOW. Thanks friend. I almost got it. With your code, raises this compile errors; [dcc32 Error] Main.pas(70): E2003 Undeclared identifier: ' MyDataLabel' [dcc32 Error] Main.pas(70): E2029 ')' expected but identifier 'JSId ' found If I try other code based in yours: uniSession.addJS ( 'if ("geolocation" in navigator) {' + ' var watchID = navigator.geolocation.watchPosition(' + ' function(position) {' + ' alert ("geolocation IS available "+ "lat:" + position.coords.latitude + ", long:" + position.coords.longitude);' + ' }' + ');' + '} else {' + ' alert ("geolocation IS NOT available");' + '}' ); This works, but have 2 problems: 1) I don't know how to return lat ans long to 2 variables (delphi variables) 2) The call to that JS is called permanently until close the browser or the browser page where is running. Any idea? Quote Link to comment Share on other sites More sharing options...
irigsoft Posted December 23, 2022 Share Posted December 23, 2022 18 hours ago, jahlxx said: the browser page where is running. I think where the unigui session is open. I use uniTimer to keep execute (every second) javascript code ! uniTimer must use ChainMode := True, Enable := True, Sequenced := False; 18 hours ago, jahlxx said: With your code, raises this compile errors; try to search by Name: ' var out = document.getElementByName ("' + MyDataLabel.JSName + '");' Quote Link to comment Share on other sites More sharing options...
jahlxx Posted December 24, 2022 Author Share Posted December 24, 2022 Ok. Thanks friend. Everything works perfect. I have tested in android cell phone. Should this work in iPhone too? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted December 24, 2022 Share Posted December 24, 2022 40 minutes ago, jahlxx said: I have tested in android cell phone. Should this work in iPhone too? https://developer.mozilla.org/en-US/docs/Web/API/Navigator#browser_compatibility Quote Link to comment Share on other sites More sharing options...
picyka Posted December 24, 2022 Share Posted December 24, 2022 procedure TUnimFormMeuAtendimento.ExecuteLocalizacao(Botao : String); begin UniSession.AddJS( 'if (navigator.geolocation) { ' + ' navigator.geolocation.getCurrentPosition( function(position) { ' + ' ajaxRequest(UnimFormMeuAtendimento.'+Botao+', "CurrentPosition" ,' + ' ["lat=" + position.coords.latitude, ' + ' "lng=" + position.coords.longitude, ' + ' "acc=" + position.coords.accuracy, ' + ' "alt=" + position.coords.altitude, ' + ' "altacc=" + position.coords.altitudeAccuracy, ' + ' "head=" + position.coords.heading, ' + ' "ts=" + position.coords.timestamp ' + ' ]);' + ' })' + '} else {alert("Localização não suportada!");}'); end; Quote Link to comment Share on other sites More sharing options...
picyka Posted December 24, 2022 Share Posted December 24, 2022 procedure TUnimFormMeuAtendimento.btnLocalizacaoDestinoClick(Sender: TObject); begin Self.ExecuteLocalizacao(TUnimButton(Sender).Name); end; Quote Link to comment Share on other sites More sharing options...
Abaksoft Posted December 24, 2022 Share Posted December 24, 2022 6 hours ago, picyka said: procedure TUnimFormMeuAtendimento.btnLocalizacaoDestinoClick(Sender: TObject); begin Self.ExecuteLocalizacao(TUnimButton(Sender).Name); end; Thank you Picyka, How does it work ? I tried, but no Alert. Can you send an example. Thx procedure TMainmForm.ExecuteLocalizacao(Botao : String); begin UniSession.AddJS( 'if (navigator.geolocation) { ' + ' navigator.geolocation.getCurrentPosition( function(position) { ' + ' ajaxRequest(UnimFormMeuAtendimento.'+Botao+', "CurrentPosition" ,' + ' ["lat=" + position.coords.latitude, ' + ' "lng=" + position.coords.longitude, ' + ' "acc=" + position.coords.accuracy, ' + ' "alt=" + position.coords.altitude, ' + ' "altacc=" + position.coords.altitudeAccuracy, ' + ' "head=" + position.coords.heading, ' + ' "ts=" + position.coords.timestamp ' + ' ]);' + ' })' + '} else {alert("Localização não suportada!");}'); end; procedure TMainmForm.UnimButton1Click(Sender: TObject); begin //Self.ExecuteLocalizacao(TUnimButton(Sender).Name); ExecuteLocalizacao('Paris'); end; Quote Link to comment Share on other sites More sharing options...
picyka Posted December 24, 2022 Share Posted December 24, 2022 2 hours ago, Abaksoft said: Obrigado Picika, Como funciona ? Eu tentei, mas nenhum alerta. Você pode enviar um exemplo. THX It serves to get the position of the cell phone's gps Quote Link to comment Share on other sites More sharing options...
jahlxx Posted December 27, 2022 Author Share Posted December 27, 2022 Ok friends. Thanks to all. Everything works perfect. Tested in android and ios devices with success. Thanks. 1 Quote Link to comment Share on other sites More sharing options...
irigsoft Posted December 27, 2022 Share Posted December 27, 2022 32 minutes ago, jahlxx said: Ok friends. Thanks to all. Everything works perfect. Tested in android and ios devices with success. Thanks. great, can you share some code? Quote Link to comment Share on other sites More sharing options...
jahlxx Posted December 27, 2022 Author Share Posted December 27, 2022 25 minutes ago, irigsoft said: great, can you share some code? Of course. Done with touch components. I 've followed these steps: 1.- In a unimform, put 2 unimedits (xlat, xlon), and a unimbutton (disabled). 2. In the onshow event of the form, this code: xlat.text := 'x'; xlon.text := 'x'; uniSession.addJS ( 'if ("geolocation" in navigator) {' + ' var watchID = navigator.geolocation.watchPosition(' + ' function(position) {' + xlat.JSName+'.setValue(position.coords.latitude);' + xlon.JSName+'.setValue(position.coords.longitude);' + ' }' + ');' + '} else {' + xlat.JSName+'.setValue("x");' + xlon.JSName+'.setValue("x");' + '}' ); 4. This ask the user to allow the app to access the location. (tested in android and an iOS cell phones) (I think that as Sherzod said in a post before, this depends of the browser, not the device). 5. If the user accept, then after a few seconds, latitude and longitude appear in the unimedits (xlat and xlon). If not, the values remains set to 'x'. 6. Give some code, to the xlat (or xlon) edit onchange event. What value is not 'x', then the button is enabled, and do what you want in the onclick event. When enabled, meand that device could be geolocated. Value 'x' means that geolocation is not done, due to the user denied the permission, and/or technical issues that didn't the browser to be able to locate the device. In my case, is mandatory to be geolocated. If not, the service will be unavailable for the user. That's all. 1 Quote Link to comment Share on other sites More sharing options...
asapltda Posted February 26 Share Posted February 26 Thanks for the example, on desktop it works, on mobile it doesn't work, could you give a possible reason? Thank you for your input Quote Link to comment Share on other sites More sharing options...
asapltda Posted February 26 Share Posted February 26 Good afternoon, the reason it doesn't work is that it requires on mobile https example https://192.168.1.xxx:8077 2 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.