Getting Google Coordinates for Google Map Datatype
I'm working on a class that triggers when a specific type of node is published. What I am trying to do is take the address, city, and zip code from the node, and use that information to get google map coordinates to plug into the google map datatype. I'm new to .net so I'm struggling. I came up with something I thougth would work, but it pops the following error when I publish a page.
No mapping exists from object type System.Net.HttpWebRequest to a known managed provider native type
So can you guys look at my code and maybe give me some pointers or links to where I might be able to get a bit more help? I've been surfing the web all morning trying to find answers already.
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Web; using umbraco.BusinessLogic; using umbraco.cms.businesslogic; using umbraco.cms.businesslogic.web; using umbraco.cms.businesslogic.media; using umbraco.cms.businesslogic.member;
namespace DistributorNodes {
public class ApplicationBase : umbraco.BusinessLogic.ApplicationBase { /// <summary> /// Initializes a new instance of the <see cref="ApplicationBase"/> class. /// </summary>
public ApplicationBase() { //Document.New += new Document.NewEventHandler(Document_New); Document.AfterPublish += new Document.PublishEventHandler(Document_New); }
The google maps datatype holds a value such as 213.213092130,123.1234884,8 (if you look in your data/Umbraco.config file you can see exactly what it holds).
So you need to be setting distributorCoordinates to a string value.
Dirk, is there a way that the datatype can automatically get the coordinates?
The issue is I have a contour form that the distributor fills out when they register, and I want to automate the process of finding the coordinates. So instead of having the distributor have to use the map datatype, I want to populate the map datatype using the address, city, and state that the distributor entered into his registration form. So on the publish event I want to get the coordinates and populate the google map datatype on the node. Does that make sense?
That's awesome! That gmaps project was the solution, just include a couple resources from that package and it makes grabbing map data super easy. Here is the final code I came up with.
using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Web;
using umbraco.BusinessLogic; using umbraco.cms.businesslogic; using umbraco.cms.businesslogic.web; using umbraco.cms.businesslogic.media; using umbraco.cms.businesslogic.member;
using Google.Api.Maps.Service.Geocoding;
namespace DistributorNodes {
public class ApplicationBase : umbraco.BusinessLogic.ApplicationBase { /// <summary> /// Initializes a new instance of the <see cref="ApplicationBase"/> class. /// </summary>
public ApplicationBase() { //Document.New += new Document.NewEventHandler(Document_New); Document.AfterPublish += new Document.PublishEventHandler(Document_New); }
Getting Google Coordinates for Google Map Datatype
I'm working on a class that triggers when a specific type of node is published. What I am trying to do is take the address, city, and zip code from the node, and use that information to get google map coordinates to plug into the google map datatype. I'm new to .net so I'm struggling. I came up with something I thougth would work, but it pops the following error when I publish a page.
No mapping exists from object type System.Net.HttpWebRequest to a known managed provider native type
So can you guys look at my code and maybe give me some pointers or links to where I might be able to get a bit more help? I've been surfing the web all morning trying to find answers already.
Hi,
Looks like you're trying to set a umbraco property to a HttpWebRequest, so this line will fail
The google maps datatype holds a value such as 213.213092130,123.1234884,8 (if you look in your data/Umbraco.config file you can see exactly what it holds).
So you need to be setting distributorCoordinates to a string value.
Make sense?
Rich
And how about using the Google maps datatype (see project section) ? No need for events to fire and do stuff?
Cheers,
/Dirk
Dirk, is there a way that the datatype can automatically get the coordinates?
The issue is I have a contour form that the distributor fills out when they register, and I want to automate the process of finding the coordinates. So instead of having the distributor have to use the map datatype, I want to populate the map datatype using the address, city, and state that the distributor entered into his registration form. So on the publish event I want to get the coordinates and populate the google map datatype on the node. Does that make sense?
Hey Chuck,
I would have a look at the source of how the Google Maps datatype gets the co-ordinates https://bitbucket.org/vertino/google-maps-for-umbraco/src then ammend your original code.
Rich
Actually Rich, I already did that, and I couldn't figure it out. I'll give it another go though... thanks.
Hey,
Having a look through the code it seems the co-ordinates are worked out in JS via the API.
How about using trying something like http://gmaps.codeplex.com/
Rich
Rich,
That's awesome! That gmaps project was the solution, just include a couple resources from that package and it makes grabbing map data super easy. Here is the final code I came up with.
is working on a reply...