MapPoint Forums

MapForums

Community of VE/MapPoint Users and Developers




Return the state that is being clicked on

This is a discussion on Return the state that is being clicked on within the MapPoint 2006/2009 Discussion forums, part of the Map Forums category; Hi everyone! I'd like to know which method should be used (I'm using C#) to return the state in which ...


Go Back   MapPoint Forums > Map Forums > MapPoint 2006/2009 Discussion

Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-02-2003
Junior Member
White Belt
 
Join Date: Mar 2003
Posts: 7
Return the state that is being clicked on

Hi everyone!

I'd like to know which method should be used (I'm using C#) to return the state in which the user has clicked (Continental United States only).

Basically, I've hooked the MouseUp method, and am trying to figure out which state the user clicks in whenever he releases his mousepointer.

How do I figure out exactly which state the person has clicked in?

(If this is easy, I'd also like to specifically highlight that state, or some other nice way of designating the state on the map itself........but it's not necessary ;) )
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 04-02-2003
Member
Yellow Belt
 
Join Date: Oct 2002
Posts: 46
I'm guessing you'll need to roll your own

I think you'll need to write the function yourself.
One way I can think to do it is grab the current location (lat/long),
Find closest point of interest. Look at the address of it, and grab the state.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 04-03-2003
Junior Member
White Belt
 
Join Date: Mar 2003
Posts: 7
Great idea! I didn't think to do that.........

The only thing I'm worried about there is if someone clicks on a border..........but I guess that'll be an extraneous case........now I just have to figure out how to do that ;)

Can you point me in the right direction bigRahn?

I just starting using MapPoint last week......still getting lost in all the controls in the object browser :roll:
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4 (permalink)  
Old 04-03-2003
Member
Yellow Belt
 
Join Date: Oct 2002
Posts: 46
Try...

Check out this article:
http://www.mp2kmag.com/articles.asp?ArticleID=45

I think it will get you going in the right direction.
If not, let me know and I'll whip something else up.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5 (permalink)  
Old 04-03-2003
Junior Member
White Belt
 
Join Date: Mar 2003
Posts: 7
Thanks again Rahn, you're a big help!

:D
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6 (permalink)  
Old 04-03-2003
Member
Yellow Belt
 
Join Date: Oct 2002
Posts: 46
Even Easier

Hey Tarren,
it gets even easier!
I was looking at the object model, and saw the "region" property of a street address.

Very easy to parse out the state.

Check out
http://msdn.microsoft.com/library/de...eetAddress.asp

Once you get it working, i'd be interested in seeing how you do it in C#.
(I'm a VB guy making the transition, so any samples would be great.)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7 (permalink)  
Old 04-08-2003
Junior Member
White Belt
 
Join Date: Mar 2003
Posts: 7
Hey Rahn!

Welp, I figured it out after much ado.

Do you want me to post the code here?
It involves hooking the MouseUp event, and working from there.....but your link certainly helped me out a great deal, and I owe you my solution in the least, let alone my gratitude!

-Tarren
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8 (permalink)  
Old 04-08-2003
Member
Yellow Belt
 
Join Date: Oct 2002
Posts: 46
Yeah, lets see the code.

Seeing the code would be great!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9 (permalink)  
Old 04-10-2003
Junior Member
White Belt
 
Join Date: Mar 2003
Posts: 7
Rahn, you need to hook the MouseUp event in whatever event you are using to load your map object as noted below....

Basically I followed how MapPoint snags its own result set after you double click an area on the map.....I sort of did this by accident. I was WriteLining the amount of results I received from the ObjectsFromPoint function, and I just happened to notice the results were the same amount of results as a double click returned.

Then I noticed the first from last item was ALWAYS the region in every case. Without fail. So, I grabbed that item in the collection of locations that are returned from ObjectsFromPoint and that is always the state!

Pretty neat eh?

(Feel free to use this code, please leave this header within!)
Code:
///Jason Pont
///4/10/03
///How to get a state from clicking anywhere on a map:
_______________________________
private class Form1()
{
private Map mUSA;

private void WhateverYouStartYourMapWith ()
{
mUSA.MouseUp += new MapPoint._MapEvents_MouseUpEventHandler(MouseUp);
}

private new void MouseUp(int button, int shift, int x, int y)
		{
			
			
		try
		{
			///Create a result set, and a default location
			/// for comparison below
			FindResults oRes;
			
//default oLoc to any valid location you want
			MapPoint.Location oLoc = (Location)mUSA.Find("12234234 Broadway Street, New York, New York, 10024");;
			
			//Grab all points of interest near the user's click
			oRes = mUSA.ObjectsFromPoint(x, y);
			
			//used in the loop below to check which result you are on
			int resultCounter = 0;
			//display count for your peace of mind
			Debug.WriteLine (oRes.Count);
			//move through the collection
			foreach (object oResultObject in oRes)
			{
				//is this object a Location object?
				if (oResultObject is Location)
				{
					//does this result set have more than 1 result?
					//if not, this is your region (oceans act like this)
					if (oRes.Count == 1)
					{
						//oLoc.Select();
						oLoc = (Location)oResultObject;
						
						//show the region in the title bar
						///THIS IS WHERE YOU GET THE STATE NAME FROM!!!!
						///Whoever needs the State name, pass it from the
						///"oLoc" object's Region property to wherever
						///you need it to go, and you're done!
						frmMapPoint.ActiveForm.Text = oLoc.Name;
						break;	
					}
					//more than 1 result....1st to last will be the region
					if (resultCounter == oRes.Count - 2)
					{
						oLoc = (Location)oResultObject;
					
						//oLoc.Select();
						
						//show the region in the title bar
						///THIS IS WHERE YOU GET THE STATE NAME FROM!!!!
						///Whoever needs the State name, pass it from the
						///"oLoc" object's Region property to wherever
						///you need it to go, and you're done!
						frmMapPoint.ActiveForm.Text = oLoc.Name.ToString();
						frmMapPoint.ActiveForm.Text = oLoc.StreetAddress.ToString();
						//Debug.WriteLine(oLoc.StreetAddress.Street.ToString());
						break;
					}
				}
				//increment which result you are currently on
				resultCounter++;
			}
		}
		catch {};	
		}//end of mouseup

}//end of form1
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
Return Pushpin Symbol Anonymous MapPoint 2006/2009 Discussion 1 04-27-2005 02:12 PM
Retrieve the clicked country name Abilio Serafim MapPoint 2006/2009 Discussion 0 04-27-2005 06:10 AM
Return surrounding Zip Codes johnweidauer MapPoint 2006/2009 Discussion 0 02-11-2004 04:58 PM
Detecting when a line is clicked on in MP2K Anonymous MapPoint 2006/2009 Discussion 1 01-21-2003 10:24 AM
When I enter just a zipcode in MapPoint, it return.... Anonymous MapPoint 2006/2009 Discussion 1 05-30-2002 08:43 PM


All times are GMT -5. The time now is 07:23 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
MP2K Magazine
Visitor Map

Short Break Ski Holidays
Just want to book a short break? Short break ski holidays become great value when you book at Holiday Hypermarket. See the range of deals on offer.

Best Travel Agent
Travel Counsellors has been named the UK's Best Travel Agent at the Guardian Unlimited Travel awards.

Holiday Italy
A Holiday in Italy can mean many different things to many different people. This diverse country has an abundance of art, wine, food and stunning beaches. Book online today.

Holidays to Mauritius
Visit the paradise island in your holidays to Mauritius. Enjoy the friendliness of the locals, the warm of the sun and the beauty of the views!

Tunisia
Tunisia enjoys excellent weather, golden beaches and a beautiful blue sea. Moving away from the beach you will find a country that has a rich and varied past. Discover the secrets of history yourself by exploring all the ruins.

Family package holidays
Save a lot of time and opt for one of the great family package holidays at Travel.co.uk

Holidays to Gran Canaria
The Canary Islands await! Book holidays to Gran Canaria online at On The Beach!


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51