How to: Create a Custom Geocode Panel
- 2 minutes to read
Do this as follows:
- Create a BingGeocodeDataProvider object and assign it to the InformationLayer.DataProvider property. Specify the object’s BingMapDataProviderBase.BingKey property.
- Customize the custom geocode panel. In this example, the panel includes two text edits (for the latitude and longitude) and the Search button.
- Call the BingGeocodeDataProvider.RequestLocationInformation method to make a location information request. In this example, the method is called in the Search button click event handler.
using System;
using System.Windows.Forms;
using DevExpress.XtraMap;
namespace MapControl_GeocodePanel {
public partial class Form1 : Form {
InformationLayer GeocodeLayer { get { return (InformationLayer)mapControl1.Layers["GeocodeLayer"]; } }
BingGeocodeDataProvider GeocodeProvider { get { return (BingGeocodeDataProvider)GeocodeLayer.DataProvider; } }
public Form1() {
InitializeComponent();
}
private void bSearch_Click(object sender, EventArgs e) {
if (String.IsNullOrEmpty(teLatitude.Text)) {
MessageBox.Show("Latitude field should be filled.");
return;
}
double latitude = Double.Parse(teLatitude.Text);
if ((latitude > 90) || (latitude < -90)) {
MessageBox.Show("Latitude must be less than or equal to 90 and greater than or equal to - 90. Correct the input value.");
return;
}
if (String.IsNullOrEmpty(teLongitude.Text)) {
MessageBox.Show("Longitude field should be filled.");
return;
}
double longitude = Double.Parse(teLongitude.Text);
if ((longitude > 180) || (longitude < -180)) {
MessageBox.Show("Longitude must be less than or equal to 180 and greater than or equal to - 180. Correct the input value.");
return;
}
GeocodeProvider.RequestLocationInformation(new GeoPoint(latitude, longitude), null);
}
}
}