This topic is locked
[SOLVED]

Get longitude and latitude for imported data

9/22/2022 11:00:17 AM
PHPRunner General questions
mbintex author

Hi,

is there any way to geolocate address data while importing? Longitude and latitude fields don“t exist in imported data and are only generated when editing the record and saving.

I guess there is a way to get long/lat programmatically, but how?

mbintex author 9/22/2022

Googled this here

https://www.codexworld.com/get-latitude-longitude-from-address-using-google-maps-api-php/

is there a PHPRunner approach with existing functions?

K
kdgsv 9/22/2022

You may find something usefull here:

https://xlinesoft.com/phprunner/docs/insert_map.htm

mbintex author 9/22/2022

Thanks, know that link.

Here it says

Enable the Geocoding option on the Choose pages screen to update latitude/longitude information each time when a record is added or updated.

No mention as far as I can see how about importing.

Of course one would have to limit the amount of imported data to not get in trouble with Google I guess.

fhumanes 9/22/2022

Hello,

I made an example with Google Map that works phenomenal, but the problem is that from the 2nd year, Google charges for the use of the service.
https://fhumanes.com/blog/integracion/servicio-restfull-api-de-google-map/

I also made another example with OpenStreetMap but services are not so good, when addresses can have problems. The advantage is that this service is free.
https://fhumanes.com/blog/guias-desarrollo/guia-6-phprunner-indicar-direccion-a-traves-de-una-mapa/

Cheers,
fernando

mbintex author 9/23/2022

Thanks Fernando,

that helps.

Really guess now that API usage with importing bigger numbers of addresses is the main problem here.

G
graham.tech4t 9/23/2022

In the UK we build a table with all the postcode sectors and then use that as a look-up to create geocodes. Equally we could create a table of all 1.8 million full postcodes and use that. Then for any records that dont get geocoded, we then use Bing mapping to do the look-ups. Bing is a lot cheaper than Google BTW. For other countries you could follow the same approach.

mbintex author 9/24/2022

@graham

There are ZIP Code databases available (and I use them for autofill purposes) and postal regions in Germany too, but I have never seen that these were somehow geocoded. Apart from that my home zip code is a region where from point a to b there are 20 kilometers - what should geocoding offer then?

G
graham.tech4t 9/25/2022

I think you would need to find the equivalent of the files we get in the UK from Royal Mail PAF, as these contain full postcodes - eg PE1 4AW - together with lat/longs. Elsewhere there are tools such as geocode.xyz that you can test as lower cost than Google/Bing but you need good addresses or accurate postcodes. In some locations we have found this tool does tend to geocode to nearest town centre, so please be aware and I suggest test fully.

Admin 9/26/2022

There is a function in PHPRunner that you can try. We haven't added it to the official API yet but we will soon.

getLatLngByAddr( $address )
returns an array with "lat", "lng"

For instance:

$location = getLatLngByAddr( "1600 Pennsylvania Avenue NW, Washington, DC 20500" );
echo $location["lat"];
echo $location["lng"];

You just need to remember that geocoding is a paid service and Google will charge $4-5 per 1000 addresses. There are other services that are cheaper, for instance I know developers from OpenCageData and can recommend them. Their cheapest plan is $50 per month though, that may be overkill for your tasks.

mbintex author 9/27/2022

@admin

that was what I was searching for.

But indeed the cost aspect kills all that in cheap SAAS