Welcome to MapForums!

Register, sign in, or use Facebook Connect above to join in and participate in the forum.

When you are signed in, this message, the ads in this row, and the red-underlined link ads all go away.

Subscribe to receive our newsletter.
Subscribe Unsubscribe
Results 1 to 9 of 9

Return the state that is being clicked on

This is a discussion on Return the state that is being clicked on within the MapPoint Desktop 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 ...

  1. #1
    Tarren is offline 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 ;) )

  2. #2
    bigRahn is offline 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.

  3. #3
    Tarren is offline 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:

  4. #4
    bigRahn is offline 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.

  5. #5
    Tarren is offline Junior Member White Belt
    Join Date
    Mar 2003
    Posts
    7
    Thanks again Rahn, you're a big help!

    :D

  6. #6
    bigRahn is offline 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.)

  7. #7
    Tarren is offline 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

  8. #8
    bigRahn is offline Member Yellow Belt
    Join Date
    Oct 2002
    Posts
    46

    Yeah, lets see the code.

    Seeing the code would be great!

  9. #9
    Tarren is offline 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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83