I've following array in php
Array
(
[0] => Array
(
[team1_score] => 10
[team2_score] => 5
[round_number] => 1
[teamtitle1] => Chennai super kings
[teamtitle2] => Spartans
)
[1] => Array
(
[team1_score] => 15
[team2_score] => 10
[round_number] => 1
[teamtitle1] => Lions11
[teamtitle2] => Kings Xl Punjab
)
[2] => Array
(
[team1_score] => 15
[team2_score] => 5
[round_number] => 1
[teamtitle1] => Zimbabwe
[teamtitle2] => Red Steel
)
[3] => Array
(
[team1_score] => 10
[team2_score] => 15
[round_number] => 2
[teamtitle1] => Zimbabwe
[teamtitle2] => Chennai super kings
)
[4] => Array
(
[team1_score] =>
[team2_score] =>
[round_number] => 3
[teamtitle1] =>
[teamtitle2] =>
)
)
I want to generate tournament brackets from this array. I'd found jquery plugin for creating tournament brackets. For generating the tournament brackets I've to form json array round wise. for round 1 it should give me 3 records for round 2 1 records and for round 3 1 record. I've tried the following code :-
<script type="text/javascript">
(function (win, doc, $) {
win.TestData<?php echo $cnt; ?> = [
<?php
foreach ($roundmatcharr as $mt => $matchval) {
if (isset($matchval["teamtitle1"]) && $matchval["teamtitle1"] != "") {
$team1 = $matchval["teamtitle1"];
} else {
$team1 = "Team 1";
}
if (isset($matchval["teamtitle2"]) && $matchval["teamtitle2"] != "") {
$team2 = $matchval["teamtitle2"];
} else {
$team2 = "Team 2";
}
if (isset($matchval["team1_score"]) && $matchval["team1_score"] != "") {
$team1score = $matchval["team1_score"];
} else {
$team1score = 0;
;
}
if (isset($matchval["team2_score"]) && $matchval["team2_score"] != "") {
$team2score = $matchval["team2_score"];
} else {
$team2score = 0;
;
}
?>
[
[{"name": "<?php echo $team1; ?>", "id": "<?php echo $team1; ?>", "seed": 1, "score": "<?php echo $team1score; ?>"}, {"name": "<?php echo $team2; ?>", "id": "<?php echo $team2; ?>", "seed": 2, "score": "<?php echo $team2score; ?>"}],
],
<?php } ?>
];
$(".my_gracket").gracket({src: win.TestData<?php echo $cnt; ?>});
})(window, document, jQuery);
</script>
It is giving me output like this:-
win.TestData = [
[
[ {"name" : "Chennai super kings", "id" : "Chennai super kings", "seed" : 1, "score" : "10" }, {"name" : "Spartans", "id" : "Spartans", "seed" : 2, "score" : "5"} ],
],
[
[ {"name" : "Lions11", "id" : "Lions11", "seed" : 1, "score" : "15" }, {"name" : "Kings Xl Punjab", "id" : "Kings Xl Punjab", "seed" : 2, "score" : "10"} ],
],
[
[ {"name" : "Zimbabwe", "id" : "Zimbabwe", "seed" : 1, "score" : "15" }, {"name" : "Red Steel", "id" : "Red Steel", "seed" : 2, "score" : "5"} ],
],
[
[ {"name" : "Zimbabwe", "id" : "Zimbabwe", "seed" : 1, "score" : "10" }, {"name" : "Chennai super kings", "id" : "Chennai super kings", "seed" : 2, "score" : "15"} ],
],
[
[ {"name" : "Team 1", "id" : "Team 1", "seed" : 1, "score" : "0" }, {"name" : "Team 2", "id" : "Team 2", "seed" : 2, "score" : "0"} ],
],
];
which is not correct. The output should be like this:-
win.TestData = [
[
[ {"name" : "Chennai super kings", "id" : "Chennai super kings", "seed" : 1, "score" : "10" }, {"name" : "Spartans", "id" : "Spartans", "seed" : 2, "score" : "5"} ],
[ {"name" : "Lions11", "id" : "Lions11", "seed" : 1, "score" : "15" }, {"name" : "Kings Xl Punjab", "id" : "Kings Xl Punjab", "seed" : 2, "score" : "10"} ],
[ {"name" : "Zimbabwe", "id" : "Zimbabwe", "seed" : 1, "score" : "15" }, {"name" : "Red Steel", "id" : "Red Steel", "seed" : 2, "score" : "5"} ],
],
[
[ {"name" : "Zimbabwe", "id" : "Zimbabwe", "seed" : 1, "score" : "10" }, {"name" : "Chennai super kings", "id" : "Chennai super kings", "seed" : 2, "score" : "15"} ],
],
[
[ {"name" : "Team 1", "id" : "Team 1", "seed" : 1, "score" : "0" }, {"name" : "Team 2", "id" : "Team 2", "seed" : 2, "score" : "0"} ],
],
];
Round 1 matches should be in first array then second and the so on.
One approach is if you first build the data into the right structure in PHP, which makes it easier to manipulate. Then you can output it as JSON using json_encode.
<?php
$rounds = [];
$output = [];
// Format data and sort by round
foreach ($roundmatcharr as $matchval) {
$match1 = new stdClass();
$match1->name = $matchval['teamtitle1'];
$match1->id = $matchval['teamtitle1'];
$match1->seed = 1;
$match1->score = $matchval['team1_score'];
$match2 = new stdClass();
$match2->name = $matchval['teamtitle2'];
$match2->id = $matchval['teamtitle2'];
$match2->seed = 2;
$match2->score = $matchval['team2_score'];
$rounds[$matchval['round_number']][] = [$match1, $match2];
}
// Extra loop to clean up round numbers
foreach ($rounds as $round) {
$output[] = $round;
}
?>
<script type="text/javascript">
(function (win, doc, $) {
win.TestData<?php echo $cnt; ?> = <?php echo json_encode($output); ?>;
$(".my_gracket").gracket({src: win.TestData<?php echo $cnt; ?>});
})(window, document, jQuery);
</script>
Related
I have a array, but for now, the array is still based on id_order, , like this :
here my controller
public function detail()
{
$data = Order::with('detail')->get();
return $data;
}
result:
[
{
"id": 1, //id_order
"order_number" : "IT.123.76",
"status" : "Pending",
"details" : [
{
"id" : 1,
"id_order" : 1,
"id_item" : 2, //based from this
"name" : "Avocado Juice",
"qty" : 7
},
{
"id" : 2,
"id_order" : 1,
"id_item" : 3, //based from this
"name" : "Orange Juice",
"qty" : 2
},
{
"id" : 3,
"id_order" : 1,
"id_item" : 5, //based from this
"name" : "Mango Juice",
"qty" : 1
}
]
},
{
"id": 2, //id_order
"order_number" : "IT.123.78",
"status" : "Pending",
"details" : [
{
"id" : 4,
"id_order" : 2,
"id_item" : 2, //based from this
"name" : "Avocado Juice",
"qty" : 1
},
{
"id" : 5,
"id_order" : 2,
"id_item" : 9, //based from this
"name" : "Ice Tea",
"qty" : 2
}
]
}
}
]
How to change the structure of the array to be like this(based id_item and name item becomes the key in each element) and also for qty per item calculated, for example = avocado juice has 2 orders, first order has qty: 7 and second order qty: 1 then sums 8 results?
[
{
"qty_total" : 8, // from 7+1 in avocado juice
"Avocado Juice" : [
{
"id" : 1, //From id_order
"id_item" : 2, //Avocado Juice
"order_number" : "IT.123.76",
"qty" : 7
},
{
"id" : 2, //From id_order
"id_item" : 2, //Avocado Juice
"order_number" : "IT.123.78",
"qty" : 1
}
]
},
{
"qty_total" : 2,
"Orange Juice" : [
{
"id" : 1, //From id_order
"id_item" : 3, //Orange Juice
"order_number" : "IT.123.76",
"qty" : 2
}
]
},
{
"qty_total" : 1,
"Mango Juice" : [
{
"id" : 2, //From id_order
"id_item" : 5, //Mango Juice
"order_number" : "IT.123.76", //order_number Id_order 1
"qty" : 1
}
]
},
{
"qty_total" : 2,
"Ice Tea" : [
{
"id" : 1, //From id_order
"id_item" : 9, //Ice Tea
"order_number" : "IT.123.78",
"qty" : 2
}
]
},
]
Thanks for advance
You can try something like this.
const orders = [
{
"id": 1, //id_order
"order_number": "IT.123.76",
"status": "Pending",
"details": [
{
"id": 1,
"id_order": 1,
"id_item": 2, //based from this
"name": "Avocado Juice",
"qty": 7
},
{
"id": 2,
"id_order": 1,
"id_item": 3, //based from this
"name": "Orange Juice",
"qty": 2
},
{
"id": 3,
"id_order": 1,
"id_item": 5, //based from this
"name": "Mango Juice",
"qty": 1
}
]
}, {
"id": 2,
"order_number": "IT.123.78",
"status": "Pending",
"details": [
{
"id": 4,
"id_order": 2,
"id_item": 2, //based from this
"name": "Avocado Juice",
"qty": 1
},
{
"id": 5,
"id_order": 2,
"id_item": 9, //based from this
"name": "Ice Tea",
"qty": 2
}
]
}
];
var ordersById = {};
orders.forEach((order) => {
order.details.forEach((detail) => {
// ToDo: filter out completed/nonpending orders
let orderGroup;
if (!ordersById[detail.id_item]) {
orderGroup = {qty_total: detail.qty};
orderGroup[detail.name] = [{id: detail.id_order, id_item: detail.id_item, order_number: order.order_number, qty: detail.qty}];
ordersById[detail.id_item] = orderGroup;
} else {
orderGroup = ordersById[detail.id_item];
orderGroup.qty_total += detail.qty;
orderGroup[detail.name].push([{id: detail.id_order, id_item: detail.id_item, order_number: order.order_number, qty: detail.qty}]);
}
});
});
const result = Object.keys(ordersById).map((order_id) => { return ordersById[order_id];});;
console.log(result);
How to update members age whose name is TEST1 using yii2.?
Used below code to update , but i am specifying the indexes there , i want with out specifying the indexes.
User::updateAll([ '$set'=> ['Addresses.0.members.0.age'=>100] ],['IN','Addresses.members.name',['TEST1'] ]);
{
"_id" : ObjectId("595209b65312f48195fb2e01"),
"username" : "Test name",
"Addresses" : [
{
"address_no" : 1,
"Address" : "Test house",
"City" : "test city",
"State" : "Test state",
"Mobile" : "9999999",
"members" : [
{
"name" : "TEST1",
"age" : 35
},
{
"name" : "TEST2",
"age" : 30
},
]
},
{
"address_no" : 2,
"Address" : "2B, Test place",
"City" : "Test city",
"State" : "Test State",
"Pincode" : "12345",
"Phone" : "1234568789",
"Mobile" : 9999999999
}
],
"Beneficiaries" : [
{
"beneficiary_id" : 1,
"Name" : "Test1",
"Age" : "28",
"Sex" : "F"
}
],
"auth_key" : "esd8d89ds89ds89ds89ds",
}
there is position operator $ to do this kind of job
{
"Addresses.members.name" : "TEST2",
},
{
$set: {
"Addresses.$.members.0.age" : 40
}
}
Here I specified first index as it supports up to one level depth.
New feature might release in future to resolve this issue: https://jira.mongodb.org/browse/SERVER-831
Yii::$app->mongodb->getCollection('user')->update(['_id' => $id, 'members.name' => 'Test1'], ['$set' => [
'members.$.age' => 100,
]]);
I'm having Mongo structure like this,
"campaigns":[{
"summary" :
[ {
"postcode" : [ {
"id" : "71",
"name" : "Recall 1",
"qty" : 3,
"history" :
[ { "timestamp" : "2014-12-16 11:15:32",
{ "timestamp": "2014-12-16 11:15:53"
} ]
} ]
},
{
"postcode" :
[ {
"id" : "72",
"name" : "Recall 2",
"qty" : 1,
"history" : [ { "timestamp" : "2014-12-16 11:15:53" } ]
} ]
}]
I'm trying to i) increment qty of postcode.id : 72 ii) insert another timestamp for that same postcode id 72.
My code:
$collection->update(array("campaigns.task.id" => $b,"_id"=> new MongoId($objectid),"campaigns.0.summary.0.postcode.0.id" => $a), array('$inc' => array('campaigns.0.summary.0.postcode.0.qty' => 1)));
$collection->update(array("campaigns.task.id" => $b,"_id"=>new MongoId($objectid),"campaigns.0.summary.0.postcode.0.id" => $a),
array('$addToSet' => array('campaigns.0.summary.0.postcode.0.history' => array("timestamp"=>$now->format('Y-m-d H:i:s')))));
but postcode.id = 72 not gets updated, i'm confused with this nested subdocument can anyone suggest me the solution ?
I am retrieving artist information from the last.fm API. Here is a sample response for U2:
{
"artist" : {
"stats" : {
"playcount" : "117896887",
"listeners" : "3077194"
},
"name" : "U2",
"tags" : {
"tag" : [
{
"url" : "http://www.last.fm/tag/rock",
"name" : "rock"
},
{
"url" : "http://www.last.fm/tag/classic%20rock",
"name" : "classic rock"
},
{
"url" : "http://www.last.fm/tag/irish",
"name" : "irish"
},
{
"url" : "http://www.last.fm/tag/pop",
"name" : "pop"
},
{
"url" : "http://www.last.fm/tag/alternative",
"name" : "alternative"
}
]
},
"image" : [
{
"#text" : "http://userserve-ak.last.fm/serve/34/12369741.jpg",
"size" : "small"
},
{
"#text" : "http://userserve-ak.last.fm/serve/64/12369741.jpg",
"size" : "medium"
},
{
"#text" : "http://userserve-ak.last.fm/serve/126/12369741.jpg",
"size" : "large"
},
{
"#text" : "http://userserve-ak.last.fm/serve/252/12369741.jpg",
"size" : "extralarge"
},
{
"#text" : "http://userserve-ak.last.fm/serve/_/12369741/U2.jpg",
"size" : "mega"
}
],
"mbid" : "704acdbb-1415-4782-b0b6-0596b8c55e46",
"similar" : {
"artist" : [
{
"url" : "http://www.last.fm/music/Passengers",
"name" : "Passengers",
"image" : [
{
"#text" : "http://userserve-ak.last.fm/serve/34/4826014.jpg",
"size" : "small"
},
{
"#text" : "http://userserve-ak.last.fm/serve/64/4826014.jpg",
"size" : "medium"
},
{
"#text" : "http://userserve-ak.last.fm/serve/126/4826014.jpg",
"size" : "large"
},
{
"#text" : "http://userserve-ak.last.fm/serve/252/4826014.jpg",
"size" : "extralarge"
},
{
"#text" : "http://userserve-ak.last.fm/serve/500/4826014/Passengers+Brian+Eno++U2+as++Du.jpg",
"size" : "mega"
}
]
},
{
"url" : "http://www.last.fm/music/Bono",
"name" : "Bono",
"image" : [
{
"#text" : "http://userserve-ak.last.fm/serve/34/2511353.jpg",
"size" : "small"
},
{
"#text" : "http://userserve-ak.last.fm/serve/64/2511353.jpg",
"size" : "medium"
},
{
"#text" : "http://userserve-ak.last.fm/serve/126/2511353.jpg",
"size" : "large"
},
{
"#text" : "http://userserve-ak.last.fm/serve/252/2511353.jpg",
"size" : "extralarge"
},
{
"#text" : "http://userserve-ak.last.fm/serve/_/2511353/Bono.jpg",
"size" : "mega"
}
]
},
{
"url" : "http://www.last.fm/music/R.E.M.",
"name" : "R.E.M.",
"image" : [
{
"#text" : "http://userserve-ak.last.fm/serve/34/33444847.jpg",
"size" : "small"
},
{
"#text" : "http://userserve-ak.last.fm/serve/64/33444847.jpg",
"size" : "medium"
},
{
"#text" : "http://userserve-ak.last.fm/serve/126/33444847.jpg",
"size" : "large"
},
{
"#text" : "http://userserve-ak.last.fm/serve/252/33444847.jpg",
"size" : "extralarge"
},
{
"#text" : "http://userserve-ak.last.fm/serve/500/33444847/REM+11.jpg",
"size" : "mega"
}
]
},
{
"url" : "http://www.last.fm/music/Coldplay",
"name" : "Coldplay",
"image" : [
{
"#text" : "http://userserve-ak.last.fm/serve/34/28914.jpg",
"size" : "small"
},
{
"#text" : "http://userserve-ak.last.fm/serve/64/28914.jpg",
"size" : "medium"
},
{
"#text" : "http://userserve-ak.last.fm/serve/126/28914.jpg",
"size" : "large"
},
{
"#text" : "http://userserve-ak.last.fm/serve/252/28914.jpg",
"size" : "extralarge"
},
{
"#text" : "http://userserve-ak.last.fm/serve/_/28914/Coldplay.jpg",
"size" : "mega"
}
]
},
{
"url" : "http://www.last.fm/music/Bruce+Springsteen",
"name" : "Bruce Springsteen",
"image" : [
{
"#text" : "http://userserve-ak.last.fm/serve/34/2326566.jpg",
"size" : "small"
},
{
"#text" : "http://userserve-ak.last.fm/serve/64/2326566.jpg",
"size" : "medium"
},
{
"#text" : "http://userserve-ak.last.fm/serve/126/2326566.jpg",
"size" : "large"
},
{
"#text" : "http://userserve-ak.last.fm/serve/252/2326566.jpg",
"size" : "extralarge"
},
{
"#text" : "http://userserve-ak.last.fm/serve/_/2326566/Bruce+Springsteen+bruce.jpg",
"size" : "mega"
}
]
}
]
},
"streamable" : "1",
"bandmembers" : {
"member" : [
{
"yearfrom" : "1976",
"name" : "Bono"
},
{
"yearfrom" : "1976",
"name" : "The Edge"
},
{
"yearfrom" : "1976",
"name" : "Adam Clayton"
},
{
"yearfrom" : "1976",
"name" : "Larry Mullen, Jr."
},
{
"yearfrom" : "1976",
"name" : "Dick Evans"
},
{
"yearfrom" : "1976",
"name" : "Ivan McCormick"
},
{
"yearfrom" : "1976",
"name" : "Peter Martin"
}
]
},
"url" : "http://www.last.fm/music/U2",
"ontour" : "0",
"bio" : {
"published" : "Tue, 27 Sep 2011 15:29:59 +0000",
"yearformed" : "1976",
"summary" : "\n U2 is an Irish rock band which formed in 1976 in Dublin, Ireland. Since the band’s formation, they have consisted of Bono</a> (real name Paul Hewson) (vocals, guitar, harmonica), The Edge</a> (real name David Evans) (guitar, keyboards, backing vocals), Adam Clayton</a> (bass) and Larry Mullen, Jr.</a> (drums, percussion). The band is the biggest selling alternative rock act of all time, having sold 140 million albums worldwide as of 2008. They have won 22 Grammys and were inducted into the Rock & Roll Hall of Fame in 2005. As of 2009, they have released 12 albums and 58 singles. \n\n Read more about U2 on Last.fm</a>.\n \n ",
"placeformed" : "Dublin, Ireland",
"formationlist" : {
"formation" : {
"yearfrom" : "1976",
"yearto" : ""
}
},
"content" : "\n U2 is an Irish rock band which formed in 1976 in Dublin, Ireland. Since the band’s formation, they have consisted of Bono</a> (real name Paul Hewson) (vocals, guitar, harmonica), The Edge</a> (real name David Evans) (guitar, keyboards, backing vocals), Adam Clayton</a> (bass) and Larry Mullen, Jr.</a> (drums, percussion). The band is the biggest selling alternative rock act of all time, having sold 140 million albums worldwide as of 2008. They have won 22 Grammys and were inducted into the Rock & Roll Hall of Fame in 2005. As of 2009, they have released 12 albums and 58 singles. \n\n Read more about U2 on Last.fm</a>.\n \n \nUser-contributed text is available under the Creative Commons By-SA License and may also be available under the GNU FDL.\n ",
"links" : {
"link" : {
"rel" : "original",
"href" : "http://www.last.fm/music/U2/+wiki",
"#text" : ""
}
}
}
}
}
I want to display the summary only but I'm having trouble selecting it in my script. I've tried the following
echo $result->artist->bio->summary;
or
$output = $result->artist->bio->summary;
echo '<ul>';
foreach ($bands as $artist) {
$name ->name;
etc
}
if ($result === NULL) die('Artist not found');
If somebody could show me how to select and display one object from the returned JSON that would be great. I've tried everything I can think of or find
enter code hereobject(stdClass)[1]
public 'artist' =>
object(stdClass)[2]
public 'name' => string 'Foo Fighters' (length=12)
public 'mbid' => string '67f66c07-6e61-4026-ade5-7e782fad3a5d' (length=36)
public 'bandmembers' =>
object(stdClass)[3]
public 'member' =>
array (size=7)
...
public 'url' => string 'http://www.last.fm/music/Foo+Fighters' (length=37)
public 'image' =>
array (size=5)
0 =>
object(stdClass)[11]
...
1 =>
object(stdClass)[12]
...
2 =>
object(stdClass)[13]
...
3 =>
object(stdClass)[14]
...
4 =>
object(stdClass)[15]
...
public 'streamable' => string '1' (length=1)
public 'ontour' => string '0' (length=1)
public 'stats' =>
object(stdClass)[16]
public 'listeners' => string '3589242' (length=7)
public 'playcount' => string '155892081' (length=9)
public 'similar' =>
object(stdClass)[17]
public 'artist' =>
array (size=5)
...
public 'tags' =>
object(stdClass)[48]
public 'tag' =>
array (size=5)
...
public 'bio' =>
object(stdClass)[54]
public 'links' =>
object(stdClass)[55]
...
public 'published' => string 'Fri, 9 Nov 2012 21:02:30 +0000' (length=30)
public 'summary' => string '
Foo Fighters are an American rock band formed by singer/guitarist/drummer Dave Grohl in 1995 in Seattle, USA. Grohl formed the group as a one-man project after the dissolution of his previous band Nirvana in 1994. Prior to the '... (length=1384)
public 'content' => string '
Foo Fighters are an American rock band formed by singer/guitarist/drummer Dave Grohl in 1995 in Seattle, USA. Grohl formed the group as a one-man project after the dissolution of his previous band Nirvana in 1994. Prior to '... (length=1514)
public 'placeformed' => string 'Seattle, USA' (length=12)
public 'yearformed' => string '1995' (length=4)
public 'formationlist' =>
object(stdClass)[57]
...
Here is how you would parse json data:
PHP
$decodedJson = json_decode($json);
$artist = $decodedJson->{"artist"};
$bio = $artist->{"bio"};
$summary = $bio->{"summary"};
var_dump($summary);
Program Output
string(631) " U2 is an Irish rock band which formed in 1976 in
Dublin, Ireland. Since the band’s formation, they have consisted of
Bono (real name Paul Hewson) (vocals, guitar, harmonica), The
Edge (real name David Evans) (guitar, keyboards, backing vocals),
Adam Clayton (bass) and Larry Mullen, Jr. (drums, percussion).
The band is the biggest selling alternative rock act of all time,
having sold 140 million albums worldwide as of 2008. They have won 22
Grammys and were inducted into the Rock & Roll Hall of Fame in 2005.
As of 2009, they have released 12 albums and 58 singles.
Read more about U2 on Last.fm. "
Demo
This question already has an answer here:
Places Autocomplete API to get GPS coordinates from address entered
(1 answer)
Closed 8 years ago.
Suppose a very simple function to query Query Autocomplete:
$query_google_places = function ($input, array $location = null) {
$parameters = ['key' => 'AIzaSyAjCY7qYiaMv8Kkk_-D1Ha7wlRkr5neppk', 'input' => $input, 'sensor' => 'false'];
if ($location) {
$parameters['location'] = $location['lat'] . ',' . $location['lng'];
$parameters['radius'] = 10000;
}
$url = 'https://maps.googleapis.com/maps/api/place/queryautocomplete/json?' . \http_build_query($parameters);
$response = file_get_contents($url);
return $response;
};
This returns:
{
"predictions" : [
{
"description" : "Pizza Hut, Halifax, United Kingdom",
"id" : "d9274717e1e203c41287fa5936701b9584814965",
"matched_substrings" : [
{
"length" : 9,
"offset" : 0
}
],
"reference" : "CmRaAAAAyulRkdspSJ2Mr5kmlhYOC-ZT7AsKdnnwjGkFFoGHNjMWwTS5mNvQBu6FqoQ89E4U0eC-PNGN0wPD8WEYgO1if6jMmxWAqkraDFOryC8B8cWTvX333l_0UaRv_sXBIITqEhCSrz9aQB0fch-AFDS3wKG7GhTRoQw09IODWJIorqjjwCYTktkfKw",
"terms" : [
{
"offset" : 0,
"value" : "Pizza Hut"
},
{
"offset" : 11,
"value" : "Halifax"
},
{
"offset" : 20,
"value" : "United Kingdom"
}
],
"types" : [ "establishment" ]
},
{
"description" : "Pizza Hut, John William Street, Huddersfield, United Kingdom",
"id" : "a1571b1434ac1491b5f6775d9a30f8ec7798a310",
"matched_substrings" : [
{
"length" : 9,
"offset" : 0
}
],
"reference" : "CoQBdAAAADaFqqtB9NGk_v1yZdY3m6OxILfLva556GBHxHIVdPHu_R0fQCm5kCduCjKL4BgiIdoNIejet3WI7xNanaiWDpiMD1Ml7Q9EnfhypReK0N6mQIY3TxOUcmf_INhkenU3ZVL8Vk9lAxqjq5ZfxiEZk9Vv8GaEnok_OJnaRBuZdCmtEhAYs-0Qc2Zza4fLuUXIiLknGhQogPaBcUm10Y59EA5i6BWPbTNXcA",
"terms" : [
{
"offset" : 0,
"value" : "Pizza Hut"
},
{
"offset" : 11,
"value" : "John William Street"
},
{
"offset" : 32,
"value" : "Huddersfield"
},
{
"offset" : 46,
"value" : "United Kingdom"
}
],
"types" : [ "establishment" ]
},
{
"description" : "pizza hut",
"matched_substrings" : [
{
"length" : 9,
"offset" : 0
}
],
"terms" : [
{
"offset" : 0,
"value" : "pizza hut"
}
]
},
{
"description" : "Pizza Hut Delivery, Wakefield Road, Huddersfield, United Kingdom",
"id" : "0c6830de14a8e23bf971626e880201f5290ec9a6",
"matched_substrings" : [
{
"length" : 9,
"offset" : 0
}
],
"reference" : "CoQBeQAAAJnMKHhJh-IE64z6seh3sbnm4dt0h1zbMYLr4BPGCITQTZLp4lkm12HKEFw0Bt761UaZPsESrY4ha7XSXusqqRVstmRFBF2wiwF5HGMO9DhRSeIzJ8CkNvsxmlqINosGBBPUHEDQEeSOoPHn3u3MeByoLVw6AzZ9N6eTrm94hsX9EhBB9cIoXjhHjR9Tr3zBROM7GhRhpYagW9qWs9hGZ3V0o9WXfrfcXw",
"terms" : [
{
"offset" : 0,
"value" : "Pizza Hut Delivery"
},
{
"offset" : 20,
"value" : "Wakefield Road"
},
{
"offset" : 36,
"value" : "Huddersfield"
},
{
"offset" : 50,
"value" : "United Kingdom"
}
],
"types" : [ "establishment" ]
},
{
"description" : "Pizza Hut Delivery, Westgate, Halifax, United Kingdom",
"id" : "667c14a2cb5bb676bd02911e924db82fb5cbe6df",
"matched_substrings" : [
{
"length" : 9,
"offset" : 0
}
],
"reference" : "CnRtAAAAEtMYQ9N4Gmn8dpZqzHOxYGPCNP9QQ6M-gHjj2hJv2euH4gUVvDhmgazi6LcRjdYpUF41moGLr26IGc2vOPfvFg_kHTqTIYHHwiD84bu0PeEzmLzIzJw2IkGNpcW1o6weO86TW8zaUaMFZ2zNW-tynhIQFT8GvSn_q7DAoP3ytM14ExoUN3sShljpfaCWEUknvsfAjZJ_Ru4",
"terms" : [
{
"offset" : 0,
"value" : "Pizza Hut Delivery"
},
{
"offset" : 20,
"value" : "Westgate"
},
{
"offset" : 30,
"value" : "Halifax"
},
{
"offset" : 39,
"value" : "United Kingdom"
}
],
"types" : [ "establishment" ]
}
],
"status" : "OK"
}
How do I get coordinates for each result? Note, that this is server-side question.
IMO, autocompletion or query autocompletion results live in a different world than search results. Google assumes you're not supposed to need coordinates in the autocompletion list because this is not the data you will be presenting on your map or in any controller. The data you'll present will be the result of a true "search" request.
Conclusion: you're supposed to call again Google server on endpoints such as nearby search, text search or details to get the coordinates.
If you want to use details, if the user clicked on a prediction from autocomplete for example, you'll use reference attribute as a parameter of your http request to identify the clicked prediction.