www.webdeveloper.com
Results 1 to 3 of 3

Thread: extract lng and lat from file

Hybrid View

  1. #1
    Join Date
    Aug 2012
    Posts
    8

    extract lng and lat from file

    Hi,
    I would like to have a php-script that reades the "lng" and "lat" from the source of this link:
    http://www.endomondo.com/workouts/274426350/8139690

    and produces a txt file like this:
    -47.98731987077525, -15.81370208749796
    -47.81370208749796, -13.81370208749796
    ...
    ...


    In other words, it should search for the lng and lat, and find the numbers and then finally produce a file with longitude- and latitude numbers one each line

  2. #2
    Join Date
    Nov 2013
    Posts
    33
    you could try something like.
    PHP Code:
    $start_from "\"data\": [";
    $ends_at    "]";

    $file "http://www.endomondo.com/workouts/274426350/8139690";
    $output getjsonobject(file_get_contents($file),$start_from,$ends_at);

    function 
    getjsonobject($file$start$end){
        
    $r explode($start$file);
        if (isset(
    $r[1])){
            
    $r explode($end$r[1]);
            return 
    '[' $r[0] . ']';
        }
        return 
    '';
    }

    $json json_decode($outputtrue);

    $lng_lat = array();
    foreach(
    $json as $k => $v){
        
    $lng $v['lng'];
        
    $lat $v['lat'];
        
    $lng_lat[] = 'lng : ' $lng ', lat : ' $lat;
    }

    //do stuff here to put it in a txt file.
    print_r($lng_lat); 

  3. #3
    Join Date
    Aug 2012
    Posts
    8
    Thanks a lot!! This really worked!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles