This topic is locked
[SOLVED]

 Database API - Insert - Update

7/28/2020 5:16:41 PM
PHPRunner General questions
Myr0n author

Is it possible to implement in the Insert and Update the capability to include Geocoding feature to add or update the latitude and longitude?

Will be nice to have that feature.

Or is possible to generate the latitude and longitude using setUpdatedLatLng ?

Thank you

Myr0n author 7/28/2020



This?

https://xlinesoft.co...eb-application/


Unfortunately no,

https://xlinesoft.co...s/geocoding.htm

When I do something like this



$data = array();

$data["address"] = $values["1048 north av"];
$data["cityl"] = $values["chicago"];

$data["zipcode"] = $values["60647"];

$data["state"] = $values["illinois"];
DB::Insert("shippingLabels", $data );



in my table shippingLabels I have 2 fieldsLatitude & LongitudeThe

DB::Insert will be nice to add the coordinates (lat & lon) because in my screen geocoding I set that table to "update geographical coordinates each time when record is added or edited"

Sergey Kornilov admin 7/28/2020

What you looking for is a process called reverse geocoding. There are multiple services on the web that provide this kind of API, you need to sign up and pay them based on usage.
Then in your code you can send lat/lng pair to their API and get back an address that you can save in your database.

Myr0n author 7/28/2020



What you looking for is a process called reverse geocoding. There are multiple services on the web that provide this kind of API, you need to sign up and pay them based on usage.
Then in your code you can send lat/lng pair to their API and get back an address that you can save in your database.


I don't want to go to the table_edit.php and click on edit all records and save them to get the lat & long automatically (reverse geocoding).
I already have a google map api key, what I want is to automatize the process, when I use db::insert or db::update a record by code using the Database API, insert or update the lat & long to my record.

Maybe this could be a wish list to a future release.The logic could be in db::insert and db::update

if a table has selected the option "update geographical coordinates each time when record is added or edited" then add or udate the latitude and longitude.
don't worry, I'll mark as solved this thread.

fhumanes 7/29/2020

Hello:
I think what you are looking for is in this example.
https://asprunner.com/forums/topic/27449-google-map-restful-api-service-geocoding-api/
Another issue is that what you are looking for is the coordinates where the application is running (client), which you can also solve with the plugin I just made.
https://asprunner.com/forums/topic/27641-free-plugins-for-phprunner-10-x/
Greetings,

Fernando

Myr0n author 7/29/2020

Thank you so much

I don't have any issues getting the lat&longWhat I am doing is:

$apiKey = "GoogleApiKey"; //<----YOUR-OWN-API-KEY

$url = 'https://maps.googleapis.com/maps/api/geocode/json?address='.rawurlencode($addr).'&sensor=false&key='; . $apiKey;

$resultMap = my_json_decode(myurl_get_contents($url));

if($resultMap['status'] == 'OK')

{

$result['NewAddress']= $resultMap['results'][0]['address_components'][0]['short_name']." ".$resultMap['results'][0]['address_components'][1]['short_name'];

$result['NewSector']= $resultMap['results'][0]['address_components'][2]['short_name'];

$result['NewCity']= $resultMap['results'][0]['address_components'][3]['short_name'];

$result['NewProvince']= $resultMap['results'][0]['address_components'][5]['short_name'];

$result['NewPostalCode']= $resultMap['results'][0]['address_components'][7]['short_name'];

$result['NewLatitude']= $resultMap['results'][0]['geometry']['location']['lat'];

$result['NewLongitude']= $resultMap['results'][0]['geometry']['location']['lng'];

DB::Insert("shippingLabels", $result);}



and works very well.What I would like to have in the process is, don't include the first 4 lines of this code, I would like that "DB::Insert" do the same job.

Myr0n author 7/29/2020

In the previous case I am getting the whole information from google maps but for db::insert or db::update just I would that update automatically the latitude & longitude like is doing after editing a record that has an address and the geocoding is set for that table.