Title: Automatic User Location
Last modified: August 30, 2016

---

# Automatic User Location

 *  Resolved [jbkeefer](https://wordpress.org/support/users/jbkeefer/)
 * (@jbkeefer)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/automatic-user-location/)
 * Does Geo My WordPress create user meta of lat and lon automatically for use by
   Geo My WordPress and any other custom code that might need it?
 * [https://wordpress.org/plugins/geo-my-wp/](https://wordpress.org/plugins/geo-my-wp/)

Viewing 12 replies - 1 through 12 (of 12 total)

 *  Thread Starter [jbkeefer](https://wordpress.org/support/users/jbkeefer/)
 * (@jbkeefer)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/automatic-user-location/#post-6750205)
 * It appears you store the geo data as cookies, so nothing is written to WP user
   meta. Is that true?
 *  Plugin Author [Eyal Fitoussi](https://wordpress.org/support/users/ninjew/)
 * (@ninjew)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/automatic-user-location/#post-6750209)
 * Hi,
    The visitor’s/user’s current position is indeed being saved in cookies. 
   But other information like posts location and members location ( when used with
   BuddyPress ) is saved in custom database table. You can however use a filter 
   that executes every time a user uses the current location widget/shortcode to
   retrieve his current location and save his data in user meta.
 * I can provide you with the right filter if that’s what your looking to do.
 *  Thread Starter [jbkeefer](https://wordpress.org/support/users/jbkeefer/)
 * (@jbkeefer)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/automatic-user-location/#post-6750240)
 * That is indeed what I am trying to do. I would be interested to see what you 
   hook into and the filter. In the meantime, I will take a look at the current 
   location widget/shortcode you reference. Not sure what that is.
 * Thank you for the reply.
 * jamie
 *  Thread Starter [jbkeefer](https://wordpress.org/support/users/jbkeefer/)
 * (@jbkeefer)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/automatic-user-location/#post-6750335)
 * Eyal
 * I am writing a simple plugin to write the lat lon to user meta. Dont sweat the
   filter.
 * Thanks again!
 * Jamie
 *  Plugin Author [Eyal Fitoussi](https://wordpress.org/support/users/ninjew/)
 * (@ninjew)
 * [10 years, 6 months ago](https://wordpress.org/support/topic/automatic-user-location/#post-6750336)
 * HI Jamie,
    Sorry I missed your previous reply.
 * Let me know if you change your mind about the filter.
 * Regard,
 *  Thread Starter [jbkeefer](https://wordpress.org/support/users/jbkeefer/)
 * (@jbkeefer)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/automatic-user-location/#post-6750402)
 * Eyal,
 * Well I’m back…
 * Is there any way I can try your filter solution?
 * I have a script I am working on but it’s taking me longer than I expected. Debugging
   the ajax is frustrating me, I have something that should work but it’s not, and
   I haven’t even added the automation.
 * Can you help a guy out? 🙂
 * Thank you,
 * Jamie
 *  Plugin Author [Eyal Fitoussi](https://wordpress.org/support/users/ninjew/)
 * (@ninjew)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/automatic-user-location/#post-6750403)
 * Sure,
    The action hook is
 *     ```
       do_action( 'gmw_user_current_location_submitted', $_POST['gmw_cl_location'], get_current_user_id() );
       ```
   
 * and can be found in geo-my-wp/plugins/current-location/includes/geo-my-wp-current-
   location-class.php.
 * So you can try the script below which suppose to update the user_meta of the 
   logged in user when he uses the curretn location shortcode/widget:
 *     ```
       function gmw_add_current_location_to_user_meta( $location, $user_id ) {
   
           // abort if user is logged out
           if ( empty( $user_id ) )
               return;
   
           update_user_meta( $user_id, 'latitude', $location['lat'] );
           update_user_meta( $user_id, 'longitude', $location['lng'] );
           update_user_meta( $user_id, 'address', $location['formatted_address'] );
       }
       add_action( 'gmw_user_current_location_submitted', 'gmw_add_current_location_to_user_meta', 10, 2 );
       ```
   
 * $location is array that holds all of the location fields.
 * Let me know if that helps.
 *  Thread Starter [jbkeefer](https://wordpress.org/support/users/jbkeefer/)
 * (@jbkeefer)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/automatic-user-location/#post-6750406)
 * Eyal,
 * thank you very much for taking the time to get this to me. I do appreciate it.
 * I will play with it and see how it works.
 * Peace,
 * Jamie
 *  Thread Starter [jbkeefer](https://wordpress.org/support/users/jbkeefer/)
 * (@jbkeefer)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/automatic-user-location/#post-6750407)
 * Eyal,
 * thank you very much for taking the time to get this to me. I do appreciate it.
 * I will play with it and see how it works.
 * Peace,
 * Jamie
 *  Thread Starter [jbkeefer](https://wordpress.org/support/users/jbkeefer/)
 * (@jbkeefer)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/automatic-user-location/#post-6750409)
 * Didn’t seem to work with the widget. My attempts to “get location” resulted in
   endless spinner.
 * thank you for your time with this, but if it requires user input, it’s the same
   that I have currently. I’ll just leave it as is and continue trying to debug 
   my plugin. I have to learn how to use ajax, but I think WordPress is making this
   harder than usual. 🙂
 * jamie
 *  [pankajchoyal07](https://wordpress.org/support/users/pankajchoyal07/)
 * (@pankajchoyal07)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/automatic-user-location/#post-6750461)
 * i can’t get exact user’s current location,
    can u help me out ???
 *  [Zabelator](https://wordpress.org/support/users/zabelator/)
 * (@zabelator)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/automatic-user-location/#post-6750480)
 * I have tried using this script, but it is not saving in user_meta table.
 * The widget in my search form finds an address, and re-organizes the search by
   location. So that part seems to be working fine.
 * I just get nothing saved to my user_meta table. Any help getting this working
   would be greatly appreciated.
 * Thanks.

Viewing 12 replies - 1 through 12 (of 12 total)

The topic ‘Automatic User Location’ is closed to new replies.

 * ![](https://ps.w.org/geo-my-wp/assets/icon-256x256.gif?rev=2803407)
 * [GEO my WP](https://wordpress.org/plugins/geo-my-wp/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/geo-my-wp/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/geo-my-wp/)
 * [Active Topics](https://wordpress.org/support/plugin/geo-my-wp/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/geo-my-wp/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/geo-my-wp/reviews/)

 * 12 replies
 * 4 participants
 * Last reply from: [Zabelator](https://wordpress.org/support/users/zabelator/)
 * Last activity: [10 years, 1 month ago](https://wordpress.org/support/topic/automatic-user-location/#post-6750480)
 * Status: resolved