0

I got an Error undefined offset:0 when I execute the code below in Laravel Controller.

public function index() {
        $maps = Gmaps_Geocache::all();

        $latitude1 = -7.325374900000001;    
        $longitude1 = 108.2251681;

        $latitude2 = -7.331842799999999;        
        $longitude2 = 108.2237382;

        $dataJson = file_get_contents("https://maps.googleapis.com/maps/api/distancematrix/json?units=metric&origins=".$latitude1.",".$longitude1."&destinations=".$latitude2.",".$longitude2."&key=AIzaSyCyUBu8OPh0adMWbL9McFMMDqJA9UB7jes");

        $data = json_decode($dataJson,true);
        $nilaiJarak = $data['rows'][0]['elements'][0]['distance']['text'];

        return view('maps', compact('maps','nilaiJarak'));
    }

how to solve it?

Rajat Jain
  • 1,339
  • 2
  • 16
  • 29

0 Answers0