Reputation: 9623
Hi I have used following code but sometime I didnt get the pushpin, I am using Basic key can any one please suggest me.
public MainPage()
{
InitializeComponent();
Geocode("8800 Lyra Avenue, Columbus, OH 43240", 1);
Geocode("2137 Birchwood Dr, Redmond,WA 78214,U.S.", 1);
Geocode("Santa Cruz, Duval Co., TX", 1);
}
private void Geocode(string address, int waypointIndex)
{
PlatformServices.GeocodeServiceClient geocodingService = new PlatformServices.GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
geocodingService.GeocodeCompleted += new EventHandler<TestSL.PlatformServices.GeocodeCompletedEventArgs>(geocodingService_GeocodeCompleted);
PlatformServices.GeocodeRequest request = new PlatformServices.GeocodeRequest();
request.Credentials = new TestSL.PlatformServices.Credentials();
request.Credentials.ApplicationId = ((Microsoft.Maps.MapControl.ClientTokenCredentialsProvider)(MyMap.CredentialsProvider)).Token;
request.Query = address;
geocodingService.GeocodeAsync(request, waypointIndex);
}
public void geocodingService_GeocodeCompleted(object sender, TestSL.PlatformServices.GeocodeCompletedEventArgs e)
{
MapLayer myMapLayer = new MapLayer();
MyMap.Children.Add(myMapLayer);
// create a location collection class
LocationCollection myLocationColl = new LocationCollection();
var geoResult = (from r in e.Result.Results
orderby (int)r.Confidence ascending
select r).FirstOrDefault();
if (geoResult != null)
{
Pushpin myPushPin = new Pushpin();
// set it to first found location
myPushPin.Location = new Microsoft.Maps.MapControl.Location(geoResult.Locations[0].Latitude, geoResult.Locations[0].Longitude);
ToolTipService.SetToolTip(myPushPin, geoResult.DisplayName);
// add it to location collection
// which would be used to set the map's bound
myLocationColl.Add(myPushPin.Location);
// Add the drawn point to the route layer.
myMapLayer.Children.Add(myPushPin);
}
}
Sometime i get two pushpin and Sometime I didnt get anything and sometimes i get 1 or 3. can any one please tell me why this is happening.
Upvotes: 0
Views: 137
Reputation: 17964
You should geocode all your data ahead of time and store the coordinates. Trying to geocode a bunch of addresses on the fly like this will drive up the number of transactions generated by your application. When using a basic key it can be rate limited if a bunch of requests are made in a short period of time. When the request is rate limited a flag is added to the header of the response to indicate this. This is documented at the bottom half of this page: http://msdn.microsoft.com/en-us/library/ff701703.aspx
Upvotes: 1