Set Map Language with Bing Maps JavaScript V8 API - bing-maps

In Bing Maps V7 there was an mkt param to set the language of the map. This is gone in V8 and instead the browsers default language is used:
The Bing Maps v8 web control no longer requires the use of a mkt
parameter to localize the map. If one is not provided the map will
automatically attempt to set the language of the map based on the
user’s browser settings and/or location.
But we need to set the language according to the website's user setting (which can be different from the browser language). Is there a way to set this using the Bing Maps V8 JavaScript API?

In Bing v8 we can use setLang and setMkt parameters to override the default localization setting.
please find below example for setting localization parameters:
<script type='text/javascript'
src='http://www.bing.com/api/maps/mapcontrol?callback=GetMap&setMkt=en-IN&setLang=en'
async defer>
</script>
Please find the below link from where I found this information :
https://msdn.microsoft.com/en-us/library/mt712553.aspx#Localizing the Map

Related

How do I create and use multiple independent components that depend on the same script (ie Google Maps API) in Backpack for Laravel?

I am trying to make a Create form in Laravel Backpack that has two fields: an address_google field, and a custom field based on https://github.com/abr4xas/gmaps-input-backpack, which includes the Google Maps API to render a map. Each includes an import of the Google Maps API. I'm looking for a way to build this map component as an independent backpack component, which depends on the Google Maps API, and I don't want to include the Google Maps API once for each component. Here's what I've found:
When both fields are allowed to use their default import, an error is thrown stating "You have included the Google Maps JavaScript API multiple times on this page. This may cause unexpected errors"
(image of the log here). On the actual page, the address_google field works, but the map doesn't render at all (seen here).
If I comment out the Google Maps import in the address_google field, the map does render, but the address_google field does not autocomplete (seen here).
If I comment out the Google Maps import in the map field, the address_google field will autocomplete, but the map will not render (seen here).
Finally, if I put the Google Maps import link in config/backpack/base.php in the scripts part of the array, and remove the Google Maps import on both the address_google field and map field, I can get both to render properly (seen here), but then the google maps API is imported into every admin panel in the application, and I don't want the Google Maps library to be included globally like this.
How would I include the Google Maps API, so that the two includes do not conflict each other? More generally, is there a recommended technique for creating independent Backpack components that depend on the same script when they will be used together on the same screen?
That's an interesting question. There's no default way to do that in Backpack, but here are two possible options:
Option (1) Only load the JS in your custom field type if address_google isn't loaded onpage:
{{-- resources/views/vendor/backpack/base/widgets/gmaps --}}
#if ($crud->fieldTypeNotLoaded(['type' => 'address_google']))
<script src="https://maps.googleapis.com/maps/api/js?v=3&key=XXXXXXX&libraries=places&callback=initGoogleAddressAutocomplete" async defer></script>
#endif
Option (2) Create a Backpack widget with the script:
#push('after_scripts')
<script src="https://maps.googleapis.com/maps/api/js?v=3&key=XXXXXXX&libraries=places&callback=initGoogleAddressAutocomplete" async defer></script>
#endpush
and add that widget only on Create and Update for this entity, in your setupCreateOperation() and/or setupUpdateOperation()
Widget::add([
'type' => 'gmaps_script',
]);
Of course, option 2 could be generalized as a script widget, where you pass the URL as a parameter, and maybe other attributes too.

Single Line Address for MapQuest

I'm trying to provide other map options besides just Google. Unfortunately a single HTTP query (e.g. location=123+main+street) only seems to be readily supported by Google.
I had no luck trying to find anything about embedding in the documentation and decided to email them directly:
The MapQuest business products
(https://developer.mapquest.com/documentation/) support both single
line input "location=1555+Blake+St+Denver+CO+80202+US" and the
advanced, 5-box method
("street=1555+Blake+St&city=Denver&state=CO&postalCode=80202&country=US").
Our API and SDK also lets you add the mapping/geocoding/routing
functions to your site without embedding links to the consumer site at
www.MapQuest.com.
Okay, so location=123+main+street should be supported in theory. However no example was provided. So using the iframe URL from the more client-oriented approach I tried the following without luck:
https://www.mapquest.com/embed/?location=1555+Blake+St+Denver+CO+80202+US
That just shows the map of the US as a whole.
How do I get the single HTTP query location to work for MapQuest embedding?
Correct: location=1555+Blake+St+Denver+CO+80202+US (single HTTP query).
Incorrect: street=1555+Blake+St&city=Denver (multiple HTTP queries).
It looks like a mix of MapQuest APIs and MapQuest.com. Check out the Link to MapQuest documentation. I think the Map a Location > Fielded Location is what you're after.
On this page: https://developer.mapquest.com/documentation/tools/link-to-mapquest/
Scroll down to Link to MapQuest Wizard.
Click on Map a Location.
Click on Single Line Location.
Click on the Run Sample with Embed View Specifier button.
Copy the URL from the new tab.
An example of the working MapQuest single HTTP query embedded page:
https://www.mapquest.com/embed/search/results?query=1555%20Blake%20St%20Denver%20CO%2080202&centerOnResults=1

Bing search api limit to certain sites

Can I define Bing search api only return result from subdomains from a site? For example, www.domain.com/dir/. This is something similar to what Google custom search does. But Google CSE has a hard limit on 10k/day. Is there an alternative search api available for this purpose?
You can simply put this into the query field, like this:
site:domain.com/dir/ whatIAmLookingFor
The query field can contain anything the Bing Engine supports, despite the keyword being site, it apparently supports also URLs
You can read the Bing Search API docs here.
madmuffin is correct, but I'm expanding on his answer to show how multiple sites can be searched. You can use the advanced search operator "site:" as part of your query "q" param.
Single Site Example
"heart disease" site:www.example.com
Multiple Site Example
"heart disease" (site:www.example1.com OR site:www.example2.com)

Use Chinese Bing Maps API

I am using the Bing Maps API on my website to embedd a map etc
I'd like to use their chinese API for my chinese visitors but I could only find the documentation for their "rest of the world" API. Any documentation in English on how to use their Chinese API?
Ideally, I'd only have to change this part: <script charset="UTF-8" type="text/javascript"src="http://ecn.dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=7.0"></script>
What's the equivalent for the Chinese API?
There used to be an old Chinese specific API for Bing Maps which I think you are referring to which has been deprecated for some time as the Bing Maps V7 control supports Chinese. Documentation on how to localize the Bing Maps V7 map control can be found here: http://msdn.microsoft.com/en-us/library/gg427600.aspx In this documentation you will notice that there are two documented options for Chinese:
Chinese – Hong Kong (zh - HK)
Chinese - Taiwan (zh - TW)

Bing maps pushpins in REST

I am using bing maps REST services and I need to add pushpins but surprisingly it's giving me a hard time. I found out how to easily add pushpins in AJAX services, but that would need me to include scripts and stuff to my pages which I'd really rather skip. I tried searching the internet for information on how to add pushpins in REST ( or simply an iframe with a URL ) but I failed to find any useful such. Does anyone know how I can add pushpins in REST?
EDIT: I'm using dynamic maps based on this link http://www.bing.com/maps/embed/viewer.aspx?showCopyright=false&cp=43.835109710693~25.957630157471&lvl=1&w=250&h=350&sty=r
Assuming that you are using the Bing Maps Imagery REST service, you will be able to add pushpin based on the URL parameters, see the MSDN: http://msdn.microsoft.com/en-us/library/ff701724.aspx
Here is an sample request that will allow you to add pushpins, take a look at the pp parameter:
http://dev.virtualearth.net/REST/v1/Imagery/Map/Road/47.619048,-122.35384/15?mapSize=500,500&pp=47.620495,-122.34931;21;AA&pp=47.619385,-122.351485;;AB&pp=47.616295,-122.3556;22&key=BingMapsKey
If you are using embedded maps, here is the list of parameters: http://msdn.microsoft.com/en-us/library/ee692180.aspx