Error:
Notice: Trying to get property of non-object in C: \ xampp \ htdocs \ json \ get_json.php on line 6
My php code:
<?php
$get = 'https://maps.googleapis.com/maps/api/place/autocomplete/json?&location=-18.866269,-41.9558537&radius=1&input=Rua%20Trin&types=address&language=pt_BR&key=dsdfdsfg21321erwr4rgf34gerg443g43hg34yh5t43tf3';
$VarJson = file_get_contents( $get );
$obj = json_decode($VarJson, true);
$VarRetorno = $obj['predictions']['description']= $obj->description;
echo $VarRetorno;
?>
Json that is being returned:
{ "predictions" : [ { "description" : "Rua Trinta e Quatro - Lourdes, Governador Valadares - MG, Brasil", "id" : "17ba7fa54b2d700007d97209fef6d5d3a8ff72e0", "matched_substrings" : [ { "length" : 8, "offset" : 0 } ], "place_id" : "EkBSdWEgVHJpbnRhIGUgUXVhdHJvIC0gTG91cmRlcywgR292ZXJuYWRvciBWYWxhZGFyZXMgLSBNRywgQnJhc2ls", "reference" : "CnRuAAAALZ2UYdupWz6GPbFvSYk4GXtquB7-enDBfMTxQSsFk6rMcC1Rb5ThNRwZak8lSjfFYlsaamMFuX4AuOLrYl3cJKKMUNSSx8jpgHcUQIcqFdKVk76P6saacMHUU0SVzEm2WMcJ8KQf_G3GksdGN3hgFRIQ4nPnz6ZlFNwC6dCpdZPoRBoUQ4_hj9FdRZM3JitMgsnpEpKkhnE", "structured_formatting" : { "main_text" : "Rua Trinta e Quatro", "main_text_matched_substrings" : [ { "length" : 8, "offset" : 0 } ], "secondary_text" : "Lourdes, Governador Valadares - MG, Brasil" }, "terms" : [ { "offset" : 0, "value" : "Rua Trinta e Quatro" }, { "offset" : 22, "value" : "Lourdes" }, { "offset" : 31, "value" : "Governador Valadares" }, { "offset" : 54, "value" : "MG" }, { "offset" : 58, "value" : "Brasil" } ], "types" : [ "route", "geocode" ] }, { "description" : "Rua Trinta e Dois - Ilha dos Araújos, Governador Valadares - MG, Brasil", "id" : "e7ef14e0d420b70015b02e4e1a8a5e2172aaa46c", "matched_substrings" : [ { "length" : 8, "offset" : 0 } ], "place_id" : "EkhSdWEgVHJpbnRhIGUgRG9pcyAtIElsaGEgZG9zIEFyYcO6am9zLCBHb3Zlcm5hZG9yIFZhbGFkYXJlcyAtIE1HLCBCcmFzaWw", "reference" : "CoQBdgAAAA-RPo0LCQ99BPlVWsBGmtob1LDyZR3KyfOTNrS4-04eLv2qGxBy27dHq-XKVIFkOrg2Rhr539RTYSYZhmQuuyqDijrqH-H0d2DjixHTO-hOgNYZOkzluH9oKZ0yma5OcKVr5efU0AtA97MuuLkK8bGVx6yC-5Oy0tcII0kXOhv5EhBfsg7tNwh6kZxfMQry1JkDGhQCEmwOyXb2OaTK4Bx_Zqsn1lhRcA", "structured_formatting" : { "main_text" : "Rua Trinta e Dois", "main_text_matched_substrings" : [ { "length" : 8, "offset" : 0 } ], "secondary_text" : "Ilha dos Araújos, Governador Valadares - MG, Brasil" }, "terms" : [ { "offset" : 0, "value" : "Rua Trinta e Dois" }, { "offset" : 20, "value" : "Ilha dos Araújos" }, { "offset" : 38, "value" : "Governador Valadares" }, { "offset" : 61, "value" : "MG" }, { "offset" : 65, "value" : "Brasil" } ], "types" : [ "route", "geocode" ] }, { "description" : "Rua Trinta e Oito - Ilha dos Araújos, Governador Valadares - MG, Brasil", "id" : "8966aca97bad47745f86d8231068c026a71dbe40", "matched_substrings" : [ { "length" : 8, "offset" : 0 } ], "place_id" : "EkhSdWEgVHJpbnRhIGUgT2l0byAtIElsaGEgZG9zIEFyYcO6am9zLCBHb3Zlcm5hZG9yIFZhbGFkYXJlcyAtIE1HLCBCcmFzaWw", "reference" : "CoQBdgAAAAmej8mJkhc90gbtnqoXMHogn48EFqvq3wgzyo2KjvXAnuH1yHphO7lSuKUTOx7vSi-NyZodgp6W4ZsSztzpy6ZB8p-EHEti4Re_j3znnPSMRPnSI-R0Qd5YVCskghIBvacIrYw3x9KQAf8x89FONdK0T_khElzGJDoBNDdmhgwpEhCcPCe8W0FS5xaCLx7yDVh5GhS8IdOD7YTiKfBdxJPTApGWAQtb1A", "structured_formatting" : { "main_text" : "Rua Trinta e Oito", "main_text_matched_substrings" : [ { "length" : 8, "offset" : 0 } ], "secondary_text" : "Ilha dos Araújos, Governador Valadares - MG, Brasil" }, "terms" : [ { "offset" : 0, "value" : "Rua Trinta e Oito" }, { "offset" : 20, "value" : "Ilha dos Araújos" }, { "offset" : 38, "value" : "Governador Valadares" }, { "offset" : 61, "value" : "MG" }, { "offset" : 65, "value" : "Brasil" } ], "types" : [ "route", "geocode" ] }, { "description" : "Rua Trinta e Seis - Ilha dos Araújos, Governador Valadares - MG, Brasil", "id" : "23ac369477e2deb81bfbdd4629c694fe52d6dab4", "matched_substrings" : [ { "length" : 8, "offset" : 0 } ], "place_id" : "EkhSdWEgVHJpbnRhIGUgU2VpcyAtIElsaGEgZG9zIEFyYcO6am9zLCBHb3Zlcm5hZG9yIFZhbGFkYXJlcyAtIE1HLCBCcmFzaWw", "reference" : "CoQBdgAAAFp2zMZl1_vXoPN4X_lNeFfAC-sraI_P-nDbR95Nm9Z-gvyLnHRZZVYzz70nHkCf3M4euIYQa9w1DP6ijSAHz2ceOLkHOi2SwgLN9oUTwJG_EjoNb0BzUlWTQ4dbvGXanwQhayjkdFuWmAo1FjcGPR8R8fg8xakO-rcrvDCeX1lnEhCMEhrd5FT3MkUYwC8MNKVWGhQPsMzr3_uXevpCP1qP3d6CCH_5WQ", "structured_formatting" : { "main_text" : "Rua Trinta e Seis", "main_text_matched_substrings" : [ { "length" : 8, "offset" : 0 } ], "secondary_text" : "Ilha dos Araújos, Governador Valadares - MG, Brasil" }, "terms" : [ { "offset" : 0, "value" : "Rua Trinta e Seis" }, { "offset" : 20, "value" : "Ilha dos Araújos" }, { "offset" : 38, "value" : "Governador Valadares" }, { "offset" : 61, "value" : "MG" }, { "offset" : 65, "value" : "Brasil" } ], "types" : [ "route", "geocode" ] }, { "description" : "Rua Trinta de Janeiro - Nossa Senhora das Gracas, Governador Valadares - MG, Brasil", "id" : "83856debc2c5dd47d125aef6d7fa974529efc2ad", "matched_substrings" : [ { "length" : 8, "offset" : 0 } ], "place_id" : "ElNSdWEgVHJpbnRhIGRlIEphbmVpcm8gLSBOb3NzYSBTZW5ob3JhIGRhcyBHcmFjYXMsIEdvdmVybmFkb3IgVmFsYWRhcmVzIC0gTUcsIEJyYXNpbA", "reference" : "CpQBgQAAAC_ucSTthN0tdwSGzHbskEt2FzYbIPhWscDg01WK1IrBeIvVI11Z5TEjd0AYe3hu_qQwSaLBvj08PYcmijGdL3-Lxm2YNjG7KOgHuMZwA2RBS2wE5WjSitvGOrRHLXsQl8DOpGaM_YktBatGNuYFyhXAlyVQcw3lIx2Kcl3LkH5yKP_9__Lt_vh2aJBFpDTPBBIQacC0hSPxeUwwyEj9E3R3ixoUy848UB8MLecNG91G81CxbHrHFD0", "structured_formatting" : { "main_text" : "Rua Trinta de Janeiro", "main_text_matched_substrings" : [ { "length" : 8, "offset" : 0 } ], "secondary_text" : "Nossa Senhora das Gracas, Governador Valadares - MG, Brasil" }, "terms" : [ { "offset" : 0, "value" : "Rua Trinta de Janeiro" }, { "offset" : 24, "value" : "Nossa Senhora das Gracas" }, { "offset" : 50, "value" : "Governador Valadares" }, { "offset" : 73, "value" : "MG" }, { "offset" : 77, "value" : "Brasil" } ], "types" : [ "route", "geocode" ] } ], "status" : "OK" }
I need to get only the description