• I’m using this code to dynamically add the weather widget to my page template given a specific custom post type. Is there a way I can add specific LATITUDE / LONGITUDE to this & have it work?

    <?php
    $location = get_post_meta( get_the_ID(), ‘location’, true );
    echo awesome_weather_logic( array(‘location’ => $location) );
    ?>

    Currently we set the location to a nearby city (Nederland, CO). Each of my pages are located mostly deep in the mountains, making weather different in nearby cities. It’d be super helpful if this plugin could accept lat/long! I know the OWM API allows it. Any suggestions?

    Iceroutes.org

    https://wordpress.org/plugins/awesome-weather/

Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Author Hal Gatewood

    (@halgatewood)

    It is not currently available but it is possible. I’ll add it to my list of things to incorporate and hopefully get to it soon.

    If you want to hack around with my plugin just check out the $api_query query variable and add this around line 142:

    if( isset($atts['lat']) AND isset($atts['lon']) )
    {
      $api_query = "lat=" . $atts['lat'] . "&lon" = $atts['lon'];
    }

    Then your PHP would be:

    echo awesome_weather_logic( array('location' => 'Location Name', 'lat' => 25, 'lon' => 90) );

    Hope this gets you in the right direction.

    Thread Starter secretagentmedia

    (@secretagentmedia)

    So I added the code to awesome-weather/awesome-weather.php at line 142 and received this error:

    Parse error: syntax error, unexpected ‘=’ in /home/umwsgjxw/public_html/iceroutes/wp-content/plugins/awesome-weather/awesome-weather.php on line 144

    Here’s the code from lines 126-147

    //FIND AND CACHE CITY ID
    	if( $owm_city_id )
    	{
    		$city_name_slug 			= sanitize_title( $location );
    		$api_query					= "id=" . $owm_city_id;
    	}
    	else if( is_numeric($location) )
    	{
    		$city_name_slug 			= sanitize_title( $location );
    		$api_query					= "id=" . urlencode($location);
    	}
    	else
    	{
    		$city_name_slug 			= sanitize_title( $location );
    		$api_query					= "q=" . urlencode($location);
    	}
    	if( isset($atts['lat']) AND isset($atts['lon']) )
    	{
    	  $api_query = "lat=" . $atts['lat'] . "&lon" = $atts['lon'];
    	}
    
    	// TRANSIENT NAME

    Any ideas?

    Thanks!

    Dan
    Secret Agent Media
    http://secretagentmedia.com/

    Plugin Author Hal Gatewood

    (@halgatewood)

    Change the line to this:

    $api_query = "lat=" . $atts['lat'] . "&lon=" . $atts['lon'];

    Plugin Author Hal Gatewood

    (@halgatewood)

    I will be adding this to the next version of the plugin! Thanks for the idea.

    Thread Starter secretagentmedia

    (@secretagentmedia)

    It seems to work for your example latitude & longitude, however when I edit them it still remains at 25, 90

    Also how would I do negative lat/longs?

    http://iceroutes.org/colorado/boulder-canyon/boulder-falls/

    echo awesome_weather_logic( array('location' => 'Location Name', 'lat' => 22, 'lon' => 43) );

    22,43 should be near Rio, but still says SHERPUR

    Plugin Author Hal Gatewood

    (@halgatewood)

    You’ll wrap them with apostrophes:

    echo awesome_weather_logic( array('location' => 'Location Name', 'lat' => '40.004711', 'lon' => '-105.405861') );

    Thread Starter secretagentmedia

    (@secretagentmedia)

    Thanks for all your help. It seems when manually inputting the lat/long coordinates it takes a while for it to update, I wonder if it’s something with the OMW API. I had tried that before but didn’t see a different city show up, but that appears to be working after saving & waiting a while!

    Now I’m still having an issue which I totally understand if you’re not able to help with, but I figured I’d post incase anyone else has advice or needs to build something similar.

    I am dynamically getting the LAT/LONG coordinates from the Geo My WP plugin using a shortcode for each coordinate. I think this code looks right, but everytime I refresh my page it says “BETHLEHEM”.

    function latitude()
    {
        echo do_shortcode('[gmw_post_info info="lat"]');
    }
    
    function longitude()
    {
        echo do_shortcode('[gmw_post_info info="long"]');
    }								
    
    $lat = 'latitude';
    $long = 'longitude';
    
    echo awesome_weather_logic( array(
    	'location' => 'Location Name',
    	'lat' => $lat,
    	'lon' => $long
    ) );

    I’ve also tried the following with the same results:

    function latitude()
    {
        echo do_shortcode('[gmw_post_info info="lat"]');
    }
    function longitude()
    {
        echo do_shortcode('[gmw_post_info info="long"]');
    }
    
    echo awesome_weather_logic( array(
    	'location' => 'Location Name',
    	'lat' => latitude(),
    	'lon' => longitude()
    ) );

    Also tried:

    $lat = do_shortcode('[gmw_post_info info="lat"]');
    $long = do_shortcode('[gmw_post_info info="long"]');
    echo awesome_weather_logic( array(
    	'location' => 'Location Name',
    	'lat' => $lat,
    	'lon' => $long
    ) );

    Any ideas what I’m doing wrong?

    Plugin Author Hal Gatewood

    (@halgatewood)

    I think your functions need to return the data instead of echo it:

    function longitude()
    {
        return do_shortcode('[gmw_post_info info="long"]');
    }
    Thread Starter secretagentmedia

    (@secretagentmedia)

    Soo it looks like this one is in fact working:

    $lat = do_shortcode('[gmw_post_info info="lat"]');
    $long = do_shortcode('[gmw_post_info info="long"]');
    echo awesome_weather_logic( array(
    	'location' => 'Location Name',
    	'lat' => $lat,
    	'lon' => $long
    ) );

    Im trying your recommendation as well to see how that one goes.

    Is there a way to force the location name to say ‘Weather’ or have it be dynamically populated within the awesome_weather_logic array?
    (Nearby locations to random lat/long in the mountains pick weird tiny towns noone has ever heard of)

    Plugin Author Hal Gatewood

    (@halgatewood)

    You can add another parameter: 'override_title' => 'Weather'

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Using Lat/long for weather inside of city names or OMW ID's – Is it possible?’ is closed to new replies.