Reputation: 1
I'm coding on c# with some lectures. But there is an error on web browser. That means it doesn't support this web browser. But my web browser is already fully updated. Who know how to figure out this problem? help me please.. here is image.
private void Search_data_Click(object sender, EventArgs e)
{
string street = txt_street.Text;
string city = txt_city.Text;
string state = txt_state.Text;
string zip = txt_zip.Text;
try
{
StringBuilder queryaddress = new StringBuilder();
queryaddress.Append("http://maps.google.com/maps?q=");
if (street!=string.Empty)
{
queryaddress.Append(street+","+"+");
}
if (city != string.Empty)
{
queryaddress.Append(city + "," + "+");
}
if (state != string.Empty)
{
queryaddress.Append(state + "," + "+");
}
if (zip != string.Empty)
{
queryaddress.Append(zip + "," + "+");
}
webBrowser1.Navigate(queryaddress.ToString());
}
catch(Exception ex)
{
MessageBox.Show(ex.Message.ToString(), "Error");
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
}
Upvotes: 0
Views: 1062
Reputation: 21
You can add the version that compatible with Google Maps. In this case use 11001 that is IE 11.
public Mapa()
{
InitializeComponent();
//Por defecto el web browser utiliza la versión 7 de Internet Explorer incompatible para visualizar google maps,
//con el indicador 11001 se setea a la versión 11 de Internet Explorer.
SetearVersionWebBrowser(11001);
}
private void btn_Buscar_Click(object sender, EventArgs e)
{
try
{
//Asignación de los valores de los texbox
string provincia = txt_provincia.Text;
string ciudad = txt_ciudad.Text;
string calle = txt_calle.Text;
string codigoPostal = txt_postal.Text;
StringBuilder direccion = new StringBuilder();
direccion.Append("http://maps.google.com/maps?q=");
//Condicionales para validar que si los campos están vacios no se tome ese criterio
if (calle != string.Empty) {
direccion.Append(calle + "," + "+");
}
if (ciudad != string.Empty)
{
direccion.Append(ciudad + "," + "+");
}
if (provincia != string.Empty)
{
direccion.Append(provincia + "," + "+");
}
if (codigoPostal != string.Empty)
{
direccion.Append(codigoPostal + "," + "+");
}
//Xpcom.EnableProfileMonitoring = false;
//Xpcom.Initialize("Firefox");
//Carga el documento espeficiado en la variable direccion
webBrowser1.Navigate(direccion.ToString());
}
catch (Exception ex) {
MessageBox.Show(ex.Message.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void SetearVersionWebBrowser(int ie_version)
{
//String de la Ruta donde se registrará el Dword
const string key32bit =
@"SOFTWARE\Microsoft\Internet Explorer\MAIN\" +
@"FeatureControl\FEATURE_BROWSER_EMULATION";
//Se obtiene el nombre del programa en ejecución
string app_name = System.AppDomain.CurrentDomain.FriendlyName;
// You can do both if you like.
//Registra el Dword con los parámetros el primero la ruta, el segundo con el nombre PruebaGrafica.vshost.exe, el tercero con la versión de internet explorer que se quiere ejecutar
SetearRegistroDword(key32bit, app_name, ie_version);
}
//Método que registra un valor DWORD
private void SetearRegistroDword(string nonmbreLlave, string nombreValor, int valor)
{
// Registro de la clave.
RegistryKey key = Registry.CurrentUser.OpenSubKey(nonmbreLlave, true);
// Se crea la clave solo si no existe.
if (key == null)
key = Registry.CurrentUser.CreateSubKey(nonmbreLlave, RegistryKeyPermissionCheck.ReadWriteSubTree);
// Establece un nombre, la clave de registro y el tipo de datos del registro especificado.
key.SetValue(nombreValor, valor, RegistryValueKind.DWord);
// Cierra la clave
key.Close();
}
Upvotes: 0
Reputation: 530
The problem is that webbrowser control uses Internet Explorer 7. You have to tell the computer to use ie11.
Follow this tutorial: http://weblog.west-wind.com/posts/2011/May/21/Web-Browser-Control-Specifying-the-IE-Version
Here's more information http://weblog.west-wind.com/posts/2011/May/21/Web-Browser-Control-Specifying-the-IE-Version
you have to add a key in the windows register and then restart your application. That worked for me.
Hope this helps.
Reference: https://www.codeproject.com/questions/998563/how-to-display-google-maps-in-webbrowser-control-u
Solution 2:
You can take a look at DotNetBrowser library that allows embedding a Chromium-based WPF component into your .NET application. It has very powerful and simple API. The following sample demonstrates how to create Browser instance and load a web page.
Upvotes: 1