Update: Due to a change in the Bing Maps REST Web Service, the steps outlined in this blog post no longer work. We are looking into the possibility of using a different API, and will update this post soon with details.
Hi, Phil Newman here from the InfoPath team. In this post, I’ll explain how to use the new REST Web service data connection in InfoPath 2010 to add a dynamic map to a contacts form. The form connects to two Web services. The first is a REST Web service that returns the coordinates of a given address from Bing Maps, the second returns an image of a map for a given coordinate set. When users enter address information in the form, the map will update to display the specified address.
The following steps assume that:
The next step is to create a rule to change the parameters in the REST Web Service URL based on the address values entered in the form. The Web service will then be queried using these parameters.
(NOTE – the button is being used as a temporary placeholder for creating the rules. In InfoPath 2010, you can copy and paste rules between controls. We’ve built in smarts so that when you copy a rule to a different control, field references are updated. In this case we do not want the references to be updated so we will create the rules on the button and then copy and paste it on to the Address fields.)
concat("http://dev.virtualearth.net/Services/v1/GeocodeService/GeocodeService.asmx/Geocode?culture=en-us&count=10&query=", Address, ", ", City, ", ", State/Province, "&landmark=&addressLine=&locality=&postalTown=&adminDistrict=&district=&postalCode=&countryRegion=&mapBounds=¤tLocation=&curLocAccuracy=&entityTypes=&rankBy=&key=YourBingMapsKey")
To display the map of the current location in the picture control, append the latitude and longitude values returned by the Bing Maps REST Web Service to the URL for that image.
concat("http://api.tiles.virtualearth.net/api/GetMap.ashx?ppl=24,,", Latitude, ",", Longitude, "&key= YourBingMapsKey")
Now, open the form in the browser and fill it out. As soon as you have entered an address, the map of that location will appear in the form.
Please leave a comment if you have any questions or feedback about this feature!
Cool idea to make the forms richer! I decided to try it out, but my form didn't show any map pictures. Some troubleshooting pointed me to the two URL's you use in your blog:
http://dev.virtualearth.net/Services/v1/GeocodeService/GeocodeService.asmx gives me a Runtime Error.
http://api.tiles.virtualearth.net/api/GetMap.ashx gives me a HTTP 400 Bad Request.
Could it be that I need to use different URL's?
I just tried using the form from the video and everything is still working. I do, however, get failures when I try to access the URLs from your comments. The services that I'm using are not yet in full production so it's expected that they might fail if you don't provide any parameters.
Did you hook up your fields in the form to the URL using the expressions builder? Can you try outputting the new REST URL to a text box and trying that in the browser to see if that works? Any additional information that you can provide would be helpful.
Thanks for your reply!
I didn't change anything in my form, but when I opened it just now, to do some more checking, it worked like a charm!
Thanks again :-)
Looks good. But is InfoPath now requiring the user to know if they are connecting to a soap or rest web service? How will a power user know what to select?
We are expecting form designers to know which type of Web service they are using. For most of the web services I've seen, the technology they use is documented along with instructions on how to use them.
SOAP and REST web services are very different in the way that you interact with them. In a nutshell, you pass parameters to REST Web services in InfoPath by changing parameters in the URL while for SOAP Web services, the URL doesn't change and parameters are set using query fields in the form. Please let me know if you have any other questions.
I used the picture control but it doesn´t work fine.
Can you provide more details on the problem you're having.
Thank you for such a great post.
Can you please upload the XSN file you have worked on the above feature.
Not sure, why Picture control does not work out for me.
Ref : When the Rule executes, it produces following error Message over the picture control,
"Only base-64 encoded boinary data allowed".
Plese help !
I have a feeling you are using an embedded picture control instead of a linked picture control. Can you try re-adding the picture control and make sure that the "As a link" option is selected in the "Insert Picture Control" dialog. Let me know if that doesn't work.
Thanks for the response.
Unfortunately, embedded picture control instead of a linked picture control did not work either.
Can you please upload the xsn file instead.
Unfortunately, the .xsn won't be much help because it can only be published to the list from which it was created.
From your last comment, it looks like you're still using the embedded picture control which includes the picture data in the form as 64-bit encoded binary. Can you try re-adding the picture control checking the "As a link" option? Make sure the control is also bound to a new field. The linked and embedded picture controls have different field types. You shouldn't have to worry about any of this if you insert the linked control.
I'm trying to replicate what youre doing but I keep getting the following message when I try add the REST Web Service Data Connection:
"Infopath cannot open the XML document...
Not enough storage is available to process this command."
Please ignore my previous comment, it was a connectivity issu on my side. I was able to continue. I've followed your instructions through and successfully published my form, however when I click my geolocate button and it queries the data connection, it is giving the following error:
"A query to retrieve form data cannot be completed because this action would violate cross-domain restrictions. "
Any suggestions? Thank-you.
For this to work, InfoPath Forms Services must be configured to allow cross-domain data connections. Ask your SharePoint Administrator to check the "Allow cross-domain data access for user form templates that use connection settings in a data connection file" checkbox on the "Configure InfoPath Forms Services" page in central admin. That should solve the problem.
I sorted that out now.
Another problem though, I'm getting an error "Unable to connect to the remote server" Log ID:5566.
The environment here gets interent access through a proxy, so I assume it has something todo with that but I don't know how to get around this or tell infopath about this proxy etc. Make sense? Any ideas?