Welcome Guest, Not a member yet? Register   Sign In
Get coordinates from address
#3

(05-03-2023, 02:23 AM)JustJohnQ Wrote: In Codeigniter 3 I made a helper (which I basically copied from the internet):
PHP Code:
<?php
function geocode($address){
    $address urlencode($address);

    $url "https://nominatim.openstreetmap.org/?addressdetails=1&q=$address&format=json&limit=1";

    $ch curl_init();
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
    curl_setopt($chCURLOPT_URL,$url);
    curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
    curl_setopt($chCURLOPT_HEADERfalse);
    curl_setopt($chCURLOPT_REFERER$url);
    curl_setopt($chCURLOPT_USERAGENT"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36");

    $result curl_exec($ch);

    curl_close($ch);

    return json_decode($resulttrue);


Then I call it from a Controller:
PHP Code:
function testMe(){
    $this->load->helper('address');
    echo "<pre>";
    print_r(geocode("piazza della signoria  ,5, firenze"));
    

It is using CURL, so it may not be what you want, but it works for me.


It works fine thank's.
Reply


Messages In This Thread
Get coordinates from address - by pippuccio76 - 05-02-2023, 12:28 PM
RE: Get coordinates from address - by JustJohnQ - 05-03-2023, 02:23 AM
RE: Get coordinates from address - by pippuccio76 - 05-04-2023, 04:10 AM



Theme © iAndrew 2016 - Forum software by © MyBB