Google Place Api- at multiple location - ios4

I am using Google Place api to show location in iphone. i am using ClLocation manager class to get current location of device which will passed as parameter of api.
but it doesn't work every time at different places in multiple devices.
any help ??

check this out
http://code.google.com/apis/maps/documentation/places/#PlaceSearches
you can
its a normal web service, post a request and get an XML / JSON list
A Place Search request is an HTTP URL of the following for
https://maps.googleapis.com/maps/api/place/search/output?parameters
e.g
https://maps.googleapis.com/maps/api/place/search/json?location=-33.8670522,151.1957362&radius=500&types=food&name=harbour&sensor=false&key=AddYourOwnKeyHere
Gets the JSON output as
{
"html_attributions" : [
"Listings by \u003ca href=\"http://www.yellowpages.com.au/\"\u003eYellow Pages\u003c/a\u003e"
],
"results" : [
{
"geometry" : {
"location" : {
"lat" : -33.8719830,
"lng" : 151.1990860
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
"id" : "677679492a58049a7eae079e0890897eb953d79b",
"name" : "Zaaffran Restaurant - BBQ and GRILL, Darling Harbour",
"rating" : 3.90,
"reference" : "CpQBjAAAAHDHuimUQATR6gfoWNmZlk5dKUKq_n46BpSzPQCjk1m9glTKkiAHH_Gs4xGttdOSj35WJJDAV90dAPnNnZK2OaxMgogdeHKQhIedh6UduFrW53wtwXigUfpAzsCgIzYNI0UQtCj38cr_DE56RH4Wi9d2bWbbIuRyDX6tx2Fmk2EQzO_lVJ-oq4ZY5uI6I75RnxIQJ6smWUVVIHup9Jvc517DKhoUidfNPyQZZIgGiXS_SwGQ1wg0gtc",
"types" : [ "restaurant", "food", "establishment" ],
"vicinity" : "Harbourside Centre 10 Darling Drive, Darling Harbour, Sydney"
},
{
"geometry" : {
"location" : {
"lat" : -33.8722580,
"lng" : 151.1986550
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png",
"id" : "27ea39c8fed1c0437069066b8dccf958a2d06f19",
"name" : "Criniti's Darling Harbour",
"rating" : 3.60,
"reference" : "CnRwAAAA-5kh5WZ3m1CMTO3LslvhRtAYsrOcQP7wB9AE1bV5R6Bd46NN5wB16MtImXWQ9eS1nWVbV_j-8iXYXRpU13Efp1t_d-Dp4WfEsFcYj-_g6db1SC1vAukyeCyotjS5xrwhzqWWAhgmA4qIliWeev2u1BIQprWzxl_hkj_w3QdTiUBYKxoUDVTjF4RugJdaJWkC4n6w6pSajKw",
"types" : [ "restaurant", "food", "establishment" ],
"vicinity" : "Shop 461, 2-10 Darling Drive, Harbourside Shopping Centre, DARLING HARBOUR"
},
...additional results...
],
"status" : "OK"
}
Get XML like this
<?xml version="1.0" encoding="UTF-8"?>
<PlaceSearchResponse>
<status>OK</status>
<result>
<name>Zaaffran Restaurant - BBQ and GRILL, Darling Harbour</name>
<vicinity>Harbourside Centre 10 Darling Drive, Darling Harbour, Sydney</vicinity>
<type>restaurant</type>
<type>food</type>
<type>establishment</type>
<geometry>
<location>
<lat>-33.8719830</lat>
<lng>151.1990860</lng>
</location>
</geometry>
<rating>3.9</rating>
<icon>http://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png</icon>
<reference>CpQBjAAAAJd_vFgeIo6ogU2gDLEe85XpxRi8LwIQXSVcPS5dxGIytvbNWic7gTlGIleeFRbrP-Rs4_V6AmCcF1RtaUXcb26_Oai6k6n34Ag17Cle3pnVl740CyNpp0VT48lOf7XkMngj75wKHqnApPZ9Bfcn0myuYeEZoKXw7c3pneO4Ty8FTxDqQyLiJk8CAkodTzSn5BIQj0ovOoMS5u-ds6_jygEGxRoUbKMNq2DBZdiS16jO3yku2DOBwNI</reference>
<id>677679492a58049a7eae079e0890897eb953d79b</id>
</result>
<result>
<name>Criniti's Darling Harbour</name>
<vicinity>Shop 461, 2-10 Darling Drive, Harbourside Shopping Centre, DARLING HARBOUR</vicinity>
<type>restaurant</type>
<type>food</type>
<type>establishment</type>
<geometry>
<location>
<lat>-33.8722580</lat>
<lng>151.1986550</lng>
</location>
</geometry>
<rating>3.6</rating>
<icon>http://maps.gstatic.com/mapfiles/place_api/icons/restaurant-71.png</icon>
<reference>CnRwAAAAwE_vlF04Iix2hijlKQsJLhpvAj8hwpfXGxtc0ckpBe0d54-rk4dxn8d1ZbaPGxxYfytkf4WJ7l5UC4Zh8jFZg0MTu1S8d66BK4vb2ktpAsKkfb28i3Mrf77ORRPXXjWwRtA7PEEfMP07mjfX3Xdg-RIQwjSMECQHM5S9WAohBIVB0BoUAb4i1DW-fL9E6XbgiDnmyZKrzRE</reference>
<id>27ea39c8fed1c0437069066b8dccf958a2d06f19</id>
</result>
...additional results...
<html_attribution>Listings by <a href="http://www.yellowpages.com.au/">Yellow Pages</a></html_attribution>
</PlaceSearchResponse>

Related

How to read a particular element from array which is the part of object in handlebar file from mongodb?

Below is my mongo db json file.
I want to read the 'topic' element from array 'Addtasks' for each its object element in .hbs(handle bar) file when the route /addTask is called in express.
{
"_id" : ObjectId("5f2313cb1351d606046660fd"),
"email" : "mike#g.com",
"name" : "Mike Tyson",
"Addtasks" : [
{
"otherdetails" : "haha great!",
"website" : "asad.com",
"keywords" : "article importance, article generation, article quality",
"words" : 1000,
"topic" : "How article is generated?",
"_id" : ObjectId("5f2314011351d606046660ff")
},
{
"otherdetails" : "Not much thanks!",
"website" : "abcdxyz.co.in",
"keywords" : "niggas are great, yo whatsup!",
"words" : 2000,
"topic" : "whats your name nigga?",
"_id" : ObjectId("5f23142d1351d60604666101")
}
],
}
You can use the second arg to .find() to project the values you want.
https://mongoplayground.net/p/LLuM1sd5Raq
db.collection.find({}, {
"Addtasks.topic": 1,
name: 1, // Add whatever other fields you need as well, remove if not
email: 1,
})
Yields:
[
{
"Addtasks": [
{
"topic": "How article is generated?"
},
{
"topic": "whats your name nigga?"
}
],
"_id": ObjectId("5f2313cb1351d606046660fd"),
"email": "mike#g.com",
"name": "Mike Tyson"
}
]
If you pass in your data something like this::
res.render('mytemplate.hbs', { items: jsObject.Addtasks });
then your hbs could look like this:
<ul>
{{#each items}}
<li>{{this.topic}}</li>
{{/each}}
</ul>
(Somewhat unrelated, but that json-file is not valid JSON. JSON and javascript objects are not the same thing. )

Spotify Application artists data scraping

i would like to get all artists information like rank,active listeners,followers and increment today details. Is there any possiblity tool to get scraped whenever i want.
The Spotify API has a Get an Artist endpoint that gives you access to things like popularity, images, followers, genres, etc. It is documented here: https://developer.spotify.com/web-api/get-artist/
A response may look like this:
{
"external_urls" : {
"spotify" : "https://open.spotify.com/artist/0OdUWJ0sBjDrqHygGUXeCF"
},
"followers" : {
"href" : null,
"total" : 306565
},
"genres" : [ "indie folk", "indie pop" ],
"href" : "https://api.spotify.com/v1/artists/0OdUWJ0sBjDrqHygGUXeCF",
"id" : "0OdUWJ0sBjDrqHygGUXeCF",
"images" : [ {
"height" : 816,
"url" : "https://i.scdn.co/image/eb266625dab075341e8c4378a177a27370f91903",
"width" : 1000
}, {
"height" : 522,
"url" : "https://i.scdn.co/image/2f91c3cace3c5a6a48f3d0e2fd21364d4911b332",
"width" : 640
}, {
"height" : 163,
"url" : "https://i.scdn.co/image/2efc93d7ee88435116093274980f04ebceb7b527",
"width" : 200
}, {
"height" : 52,
"url" : "https://i.scdn.co/image/4f25297750dfa4051195c36809a9049f6b841a23",
"width" : 64
} ],
"name" : "Band of Horses",
"popularity" : 59,
"type" : "artist",
"uri" : "spotify:artist:0OdUWJ0sBjDrqHygGUXeCF"
}
You can request additional features in the Web API issue tracker here: https://github.com/spotify/web-api/issues

Artifactory AQL search for builds on promotion.status

I'm trying to use AQL to get a list of all build not promoted to "release".
Our binaries pass through status integration-> aat -> release
I want to get a list of those with promotion status integration and aat but not release.
One example of a build has statuses:
"statuses" : [ {
"status" : "integration",
"timestamp" : "2016-04-20T08:36:42.009+0000",
"user" : "user",
"ciUser" : "changes",
"timestampDate" : 1461141402009
}, {
"status" : "aat",
"repository" : "repo-aat",
"timestamp" : "2016-04-20T08:56:11.843+0000",
"user" : "user",
"ciUser" : "changes",
"timestampDate" : 1461142571843
}, {
"status" : "aat",
"repository" : "repo-aat",
"timestamp" : "2016-04-20T08:58:55.417+0000",
"user" : "user",
"ciUser" : "changes",
"timestampDate" : 1461142735417
}, {
"status" : "aat",
"repository" : "repo-aat",
"timestamp" : "2016-04-20T09:20:32.619+0000",
"user" : "user",
"ciUser" : "changes",
"timestampDate" : 1461144032619
}, {
"status" : "release",
"repository" : "repo-release",
"timestamp" : "2016-04-20T09:30:12.143+0000",
"user" : "user",
"ciUser" : "changes",
"timestampDate" : 1461144612143
}, {
"status" : "release",
"repository" : "repo-release",
"timestamp" : "2016-04-20T09:40:50.595+0000",
"user" : "admin",
"ciUser" : "changes",
"timestampDate" : 1461145250595
} ],
This build is matched regardless if we set:
{"promotion.status": {"$nmatch":"aat"}}
to
{"promotion.status": {"$nmatch":"release"}}
{"promotion.status": {"$nmatch":"integration"}}
with the request:
builds.find({
"$and" : [
{"name": {"$match": "test"}},
{"created": {"$lt": "2016-12-01"}},
{"promotion.status": {"$nmatch":"release"}}
]
}).include("promotion.status").limit(10)
we get this response:
{
"results" : [ {
"build.created" : "2016-04-20T10:12:46.905Z",
"build.created_by" : "test",
"build.modified" : "2016-04-20T11:45:12.309Z",
"build.modified_by" : "admin",
"build.name" : "user",
"build.number" : "2551",
"build.promotions" : [ {
"build.promotion.status" : "aat"
}, {
"build.promotion.status" : "integration"
} ],
"build.url" : "URL"
} ],
"range" : {
"start_pos" : 0,
"end_pos" : 1,
"total" : 1,
"limit" : 10
}
If you do not need to use wildcards with $nmatch, you can use $ne instead, for example:
builds.find({
"$and" : [
{"name": {"$match": "test"}},
{"created": {"$lt": "2016-12-01"}},
{"promotion.status": {"$ne":"release"}}
]
}).include("promotion.status").limit(10)
With $nmatch, the following will also work:
builds.find({
"$and" : [
{"name": {"$match": "test"}},
{"created": {"$lt": "2016-12-01"}},
{"promotion.status": {"$nmatch":"releas*"}}
]
}).include("promotion.status").limit(10)
What you are trying to do, is to ask Artifactory for the "most recent" status of a build, and filter based on that. However this is not how Artifactory treats your AQL query.
Please note that your build does not have a property "build.promotion.status". Instead, your build has a property of type array with the name "build.promotions". Within this array, any number of promotion history items may be set for your build, including the property "build.promotion.status".
Now suppose your AQL query is going to select builds that have "build.promotion.status" : "aat", what you are really asking Artifactory is this: please return any build for which any of the elements of the build.promotions array has a matching property "build.promotion.status" : "aat".
So eventhough the build #2551 in your example has been promoted from "aat" to "released", you are asking AQL if it did - at any point in time - have promotion status "aat", which it did.
To add to the confusion, when you include("promotion.status"), you are going to see a filtered subset of the promotion history items.
If you are trying to work around this by asking for the reverse question: which builds do not have any build status history item with "build.promotion.status" = "released", even if that would be possible with AQL, it would not tell you what the current status is. Nor would it work correctly if you build is ever "Rolled-back".
I think JFROG should actually introduce a "build.promotion.status" field, which does what people reasonably expect: to give you the current status to display and to query on. Until that time, the only solution I can think of is to fetch all the build promotion items and then do the magic in a higher order language.

Updating a specific doc in array in subdocument in MongoDb

I have a document user that have a schema as:
{
"_id" : ObjectId("57b2d706f61d04e8d99dd983"),
"addressesAsVendor" : [
{
"_id" : "V1",
"addressLine1" : "al1",
"addressLine2" : "al2",
"street" : "street",
"city" : "city",
"country" : "IN",
"pincode" : "490020",
"location" : {
"latitutde" : "lat1",
"longitude" : "lon1"
}
},
{
"_id" : "V2",
"addressLine1" : "al1",
"addressLine2" : "al2",
"street" : "street",
"city" : "city",
"country" : "IN",
"pincode" : "490020",
"location" : {
"latitutde" : "lat2",
"longitude" : "lon2"
}
}
]
}
Now let's suppose I want to update the V1 id of the addressesAsVendor array which is inside the user Id 57b2d706f61d04e8d99dd983 with the data:
{
"addressLine1" : "al1 new",
"addressLine2" : "al2 new",
"street" : "street new",
"city" : "city new",
"country" : "IN new",
"pincode" : "490020 new",
"location" : {
"latitutde" : "lat1 new",
"longitude" : "lon1 new"
}
}
So the new user doc will look like:
{
"_id" : ObjectId("57b2d706f61d04e8d99dd983"),
"addressesAsVendor" : [
{
"_id" : "V1",
"addressLine1" : "al1 new",
"addressLine2" : "al2 new",
"street" : "street new",
"city" : "city new",
"country" : "IN new",
"pincode" : "490020 new",
"location" : {
"latitutde" : "lat1 new",
"longitude" : "lon1 new"
}
},
{
"_id" : "V2",
"addressLine1" : "al1",
"addressLine2" : "al2",
"street" : "street",
"city" : "city",
"country" : "IN",
"pincode" : "490020",
"location" : {
"latitutde" : "lat2",
"longitude" : "lon2"
}
}
]
}
How this can be achieved in MongoDb and what's the best way of keeping multiple addresses, which can be easily shown in the Address page of the user and also minimum in load, I mean will be easy to access when required.
Please shed your views.
:)
You can do the update using the positional $ operator:
var data = {
"addressLine1" : "al1 new",
"addressLine2" : "al2 new",
"street" : "street new",
"city" : "city new",
"country" : "IN new",
"pincode" : "490020 new",
"location" : {
"latitutde" : "lat1 new",
"longitude" : "lon1 new"
}
};
collection.update(
{ "addressesAsVendor._id" : "V1" },
{ "$set": { "addressesAsVendor.$": data } },
function(err, result) {
if (err) return handleError(err);
console.log(result);
}
)
The positional operator in the above saves the index (0 in the case above) of the element from the array that matched the query. This means that if you knew the position of the element beforehand (which is nearly impossible in a real life case), you could just change the update statement to: { "$set": { "addressesAsVendor.0": data } }.
Since the positional $ operator acts as a placeholder for the first element that matches the query document, and the array field must appear as part of the query document hence the query { "addressesAsVendor._id" : "V1" } is essential to get the $ operator to work properly.
Please note that the positional $ operator (for now) updates the first relevant document ONLY, there is a JIRA ticket for this.
For your follow-up question which seeks to find the best way of keeping multiple addresses, which can be easily shown in the Address page of the user and also minimum in load:
Your current schema is a better approach than creating a separate collection of addresses since separate collections require more work i.e. finding a user + its addresses is two queries and requires extra work whereas the above schema embedded documents are easy and fast (single seek). There are no big differences for inserts and updates. So, separate collections are good if you need to select individual documents, need more control over querying, or have huge documents. Embedded documents are good when you want the entire document, the document with a $slice of the embedded addressesAsVendor, or with no addresses at all.
As a general rule, if you have a lot of "addresses" or if they are large, a separate collection might be best.
Smaller and/or fewer documents tend to be a natural fit for embedding.
You can use updateOne (MongoDB query) to update the document.
NodeJS equivalent is:-
collection.update(criteria, update[[, options], callback]);
Please change the object id accordingly.
db.address.updateOne({ "_id" : ObjectId("57c04425c400a6b59c9bc1ee"), "addressesAsVendor._id" : "V1" }, { $set: { "addressesAsVendor.$.addressLine1" : "al1 new",
"addressesAsVendor.$.addressLine2" : "al2 new",
"addressesAsVendor.$.street" : "street new",
"addressesAsVendor.$.city" : "city new",
"addressesAsVendor.$.country" : "IN new",
"addressesAsVendor.$.pincode" : "490020 new",
"addressesAsVendor.$.location" : {
"latitutde" : "lat1 new",
"longitude" : "lon1 new"
}
} });

Upsert embedded object in mongoDB

Given this Person collection:
{
"_id" : ObjectId("4f8e95a718bcv9c74da1e6511a"),
"name" : "John",
"hobbies" : [{
"id" : 001,
"name" : "reading",
"location" : "home"
},{
"id" : 002,
"name" : "sport",
"location" : "outside"
}]
}
and these new/edited Hobby objects:
{
"name" : "walking",
"location" : "outside"
}
and
{
"id" : 001,
"name" : "reading",
"location" : "outside"
}
If I know the Person that I want to manage, what is be the best way to upsert embedded objects?
Currently my approach is to find the Person object, make the required modifications to it in my code, and then save it back to the DB. This works. But I'd like to simplify and reduce the number of round trips to the database.

Resources