I'm looking for a simple way to bring up a MapQuest map with something like:
http://mkapquestapi.com?address=123 Mapel St. Mytown, CA&diameter=20 miles
All the MapQuest documentation I've found tries to put me through hundreds of pages that do much more than I want.
I came across the example below in another StackOverflow question:
$.ajax({
url: "http://www.mapquestapi.com/geocoding/v1/address?key=",
dataType: 'json',
type: 'POST',
contentType:'json',
data: {location: { "postalCode": "98765"}, options: { thumbMaps: false} },
success: function(data) { log( data ) },
error: function(data) { log( 'error occurred - ' + zipCode + ' - ' + data ) }
});
I could handle something like that if someone could point me to where MapQuest explains what it wants in the parameters.
Thanks for any help.
So you want to open MapQuest with an address, rather than lat/long coordinates?
The parameter options are defined in the MapQuest geocoding parameters section. Try this:
http://www.mapquestapi.com/geocoding/#parameters
Disclaimer: I work at MapQuest.
What exactly are you looking to do --- are you looking to generate an image of a map with an address marked on it?
If so, you can use the Static Map API. Here's an example: http://www.mapquestapi.com/staticmap/v4/getplacemap?key=YOUR_KEY_HERE&location=1555 Blake St, Denver, CO&size=400,200&type=map&zoom=13&imagetype=jpeg&showicon=red_1-1
More documentation is here: http://www.mapquestapi.com/staticmap/
If you are looking to make a link that opens MapQuest.com and displays an address, you can link to it this way: http://mapq.st/map?q=1555 Blake St Denver CO 80202&maptype=map
More documentation is here: http://www.mapquestapi.com/link-to-mapquest/
Let me know if this helps. Sounds like you're looking for a map or a map image and not a geocoding result.
Related
Is it possible to filter boundary tilesets by ISO 3166-1 alpha-3 country code? And if yes, then how? I've searched in the documentation, but haven't found anything. This is how I currently filter the tileset by 2 characters country code iso_3166_1. I've tried to change it from 'iso_3166_1' to 'iso_3166_1_alpha_3', as found in reference to something different, but it doesn't work.
mapBox.on('load', () => {
mapBox.addSource('admin-1', {
type: 'vector',
url: 'mapbox://mapbox.boundaries-adm1-v3'
});
var countriesToDisplay: Array<string> = ['US', 'NZ']
countriesToDisplay.forEach((countryCode: string) => {
mapBox.addLayer({
id: 'admin-1-fill-' + countryCode,
type: 'fill',
source: 'admin-1',
'source-layer': 'boundaries_admin_1',
filter: ['any', ['all', ['==', ['get', 'iso_3166_1'], countryCode]]],
paint: { 'fill-color': '#044e9c' }
}, 'waterway-label');
});
});
Mapbox Boundaries v3 tileset only has a few features in the actual tiles, for polygons they are:
id
iso_3166_1
worldview
Checkout the full reference documentation here: https://docs.mapbox.com/vector-tiles/reference/mapbox-boundaries-v3/#polygon-tileset-reference
The rest of the data is stored in the supplemental look up tables that you are sent when you purchase the tileset. You can see all the properties available here: https://docs.mapbox.com/help/tutorials/get-started-mapbox-boundaries/#feature-lookup-tables
You will need to perform a data join to make the data from these lookup tables accessible to you in your javascript. There is a tutorial that walks you through that here: https://docs.mapbox.com/help/tutorials/data-joins-with-mapbox-boundaries/
I tried to create a list of objects using comprehension in Coffeescript..
photos =
lat: r.latitude
lng: r.longitude
url: r.url
caption: r.contentName
thumbnail: r.url
video: null
for r in res
But it will not work.. Does anyone have ideas about this?
That code creates a single object in photos and then loops over res without the loop doing anything. You want to say:
photos = for r in res
lat: r.latitude
lng: r.longitude
url: r.url
caption: r.contentName
thumbnail: r.url
video: null
If you wanted to do it in the one-liner form, you'd have to say:
photos = (lat: r.latitude, ... for r in res)
with a big mess to create the object in place of the ... of course. And yes, the parentheses are required if you wanted to do it that way due to the high precedence of assignment.
I'm looking for ways to reduce my bing maps query response size. For example - If I'm interested in the road distance between Seattle and LA, I'd query:
http://dev.virtualearth.net/REST/V1/Routes?wp.0=seattle&wp.1=losangeles&key=
(sorry, you'll have to use your own key)
... and that would give me something this (~1kB):
{
...
[
{
estimatedTotal: 1,
resources:
[
{
__type: "Route:http://schemas.microsoft.com/search/local/ws/rest/v1",
bbox:
[
34.053493,
-123.393781,
47.604151,
-118.242588
],
id: "v65,h-1259215200,i0,a0,cen-US,dAAAAAAAAAAA1,y0,s1,m1,o1,t4,w5D47BElTIPU1~ArgmUSjRxBABAADgAVva_j4A0~U2VhdHRsZSwgV0E1~~~,w9ecGAxFDffU1~ArgmUSgxwaIFAADgAQw_AT8A0~TG9zIEFuZ2VsZXMsIENB0~~~,k1",
distanceUnit: "Kilometer",
durationUnit: "Second",
routeLegs:
[],
travelDistance: 1827.815,
travelDuration: 58573,
travelDurationTraffic: 60478
}
]
}
],
...
This would look good, except expanding the routeLegs node gives me another ~23kB of data in the response - the full route - which I don't need. Anyone knows a way how to filter this out (either routeLegs or any of the underlying nodes?)
Thanks
You can now use the routeAttributes parameter documented here: https://msdn.microsoft.com/en-us/library/ff701717.aspx
I am using the Facebook Graph API to return a list of Facebook friends. I then want to run the returned JSON into Typeahead.js as follows:
$(document).ready(function () {
$('input.friends').typeahead({
name: 'friends',
prefetch: 'https://graph.facebook.com/me/friends?access_token=<?php echo $access_token;?>',
ttl: 0,
template: [
'<p class="name-tag">{{name}}</p>'
].join(''),
engine: Hogan
});
});
My corresponding HTML is as follows:
<input class="friends typeahead" type="text" placeholder="Start typing" id="friends">
But nothing is being returned using the prefetch (with hardcoded, local values, no problem). I am not seeing any errors in the console regarding cross-domain issues.
I am fairly sure this is because Typeahead hasn't been told how to handle the JSON structure, but I am unsure how to achieve this. I have tried implementing the templating system Hogan (which I will admit to being unfamiliar with) but this has not helped.
Any ideas much appreciated.
Many thanks
You need to either use valueKey if the result is a simple list of objects, from which you want to use a specific key as your values, or alternatively use a filter: to convert the result into a flat list of suggestions.
In your case, the response is a object with a data member that is a list of name, id pairs. You can have filter() be a function that returns response.data (to extract the list from the data member), and then set valueKey to name.
Thanks Nitzan.
My code snippet currently looks like:
valueKey: 'name',
remote: {
url: 'https://graph.facebook.com/me/friends?access_token=<?php echo $access_token;?>',
filter: function (response) {
return response.data;
},
},
template: [
'<p>{{name}}</p>',
].join(''),
engine: Hogan
Which returns ALL the names in the JSON at once, no matter what is in the input box.
Is this a problem with the filter or something else?
Solution below. Remember to include Hogan if you're using that as your templating engine, as I have done:
$.get('https://graph.facebook.com/me/friends?access_token=<?php echo $access_token;?>', function(server_data){
var rt = {};
for (var i in server_data.data)
rt[server_data.data[i].id] = {name:server_data.data[i].name, id:server_data.data[i].id},
//rt.push({name:server_data.data[i].name})
console.log(rt)
$('input.friends').typeahead({
limit: 10,
name: 'friends',
valueKey: 'name',
local:rt,
template: [
'{{id}}',
].join(''),
engine: Hogan
});
})
I'm trying to filter my results from a Rest Call.
$.ajax({
type: "GET",
headers: {
"Accept": "application/json;odata=verbose"
},
dataType: "JSON",
url: _spPageContextInfo.webServerRelativeUrl + "/_api/lists/getByTitle('Contacts')/items?$select=Title,Id&$startswith('Title','" + request.term + "') eq true",
success: function (data) {
},
error: function (ex) {
}
});
In my Contacts List i'm trying to retrieve the Title and the Id for Items which start with a String or which have the String somewhere in it, here for example it is the Name of somebody.
I also tried it with substringof:
"/_api/lists/getByTitle('Contacts')/items?$select=Title,Id&$substringof(" + request.term + ",'Title') eq true"
which delivers also the same result.
It gives me all List Items from the List and no Filtering is applied.
I build the Url for the Rest after looking here Programming using the SharePoint 2013 REST service
Like the Schema given there I think the Url looks ok, but it not seems so :)
Edit:
Applying the $filter like in the OData Uri Conventions gives me the following error:
{"error":{"code":"-1, Microsoft.SharePoint.SPException","message":{"lang":"en-US","value":"The query is not valid."}}}
Tried it with following Query Strings:
_api/lists/getByTitle('Contacts')/items?$select=Title,Id&$filter=substringof(m,'Title') eq true
_api/lists/getByTitle('Contacts')/items?$select=Title,Id&$filter=substringof('m','Title') eq true
_api/lists/getByTitle('Contacts')/items?$select=Title,Id&$filter=substringof('m',Title) eq true
I've managed to get the filter with substringof returning the correct results when I removed the "eq true".
Using one of your query strings, it should work like this:
_api/lists/getByTitle('Contacts')/items?$select=Title,Id&$filter=substringof('m',Title)
I haven't checked any other functions, but at least, the same happens with startswith function.
For anyone looking at this question, I can report that
/_api/web/lists/GetByTitle('Applications')/items?$filter=startswith(Title,'1AAJ')
IS working for me.
I tried your query URI on my endpoint and applied some changes:
- The second parameter of the substring shouldn't be a string, so I removed the apostropes
After this I get the results:
http://jaydata.org/examples/Northwind.svc/Products?$select=Product_ID,Product_Name&$filter=substringof('CH',Product_Name)
My endpoint is standard WCF Data Service, and the filter is working.
If changing the URI still returns all records, that would be a SherePoint trick I guess. What happens if you put 'zzz' or some random string in the filter?
Check http://www.odata.org/documentation/odata-v2-documentation/uri-conventions/ for the correct uri convention.
Should be
/_api/lists/getByTitle('Contacts')
/items?$select=Title,Id&$filter=substringof(" + request.term + ",'Title') eq true"
So with the $filter included
Also, the contains method works and I've had better compatibility with it. The syntax is:
api/People?$filter=contains(LastName,%27Smith%27)&$select=LastName,FirstName