cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Merel
Advocate II
Advocate II

Show weather based on user location

Hi guys!

 

I'm trying to build an app to put on my SharePoint intranet site that provides some personalization. Right now I'm trying to show the weather based on the user's location. Ideally, the app would show the city of the user's current location + the weather for that city.

 

I have managed to show the precise address of the user by setting the OnVisible property of the screen to 

 

Set(myLocation, BingMaps.GetLocationByPoint(Location.Latitude, Location.Longitude))

 

Then adding a text box with myLocation.name

 

What I would now like to do is:

  • From this exact address, show JUST the City name (incl. perhaps the Country name), and
  • Using this city, show the weather for that city.

 

Everything I've tried so far has not worked. Anyone any ideas...?

 

Thanks!

 

Merel

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @Merel :

Do you want to get the users current location and the current weather for that city?

Firstly, I want to explain why you encounter this problem.

The key is to use a connector with "weather" functionality.(BingMap does not has the feather about whether)

I suggest you use MSN Weather connection here.

In addition, Location.Latitude&","&Location.Longitude is enough. For convenience, we do not need to use BingMaps here.

Secondly, Ive made a test for your reference:

Case1:use BingMap

1/add a button and set its OnSelect property to:

Set(myLocation, BingMaps.GetLocationByPoint(Location.Latitude, Location.Longitude));
Set(myweather,MSNWeather.CurrentWeather(myLocation.address.addressLine,"Metric"))

2/add three label controls(Label1/ Label2/ Label3) and set their Text property to:

Label1:

"Area:"& myweather.responses.source.location

Label2:

"CAP:"& myweather.responses.weather.current.cap

Label3:

"Temp:"& myweather.responses.weather.current.temp&myLocation.units.temperature

Case2:do not use BingMap

1/add a button and set its OnSelect property to:

Set(myweather,MSNWeather.CurrentWeather(Location.Latitude&","&Location.Longitude,"Metric"))
 

Best Regards,

Bof

View solution in original post

4 REPLIES 4
Max44
Helper V
Helper V

Well... First of all there is no need to use WebServices, but you can't do it without any API. As I can see you use openweathermap API . As far as I know this API returns both longitude and latitude, so you can use these values as input to another request to a photo API (like flickr) to get the image you want. Moreover openweathermap API returns city name which can make your photo request even more accurate.

 

Hi @Max44 ,

 

Thanks for your swift reply! I'm not sure I totally understand, though.

 

I'm not trying to get a photo, just city name (and maybe country) but more importantly the weather for the current user.

 

I have used the Bing Maps API to pinpoint the user's location but after that I'm stuck. Is it not possible to do this using Bing Maps API & the built in MSN Weather connection?

 

Thanks again!

Merel

Hi @Merel :

Do you want to get the users current location and the current weather for that city?

Firstly, I want to explain why you encounter this problem.

The key is to use a connector with "weather" functionality.(BingMap does not has the feather about whether)

I suggest you use MSN Weather connection here.

In addition, Location.Latitude&","&Location.Longitude is enough. For convenience, we do not need to use BingMaps here.

Secondly, Ive made a test for your reference:

Case1:use BingMap

1/add a button and set its OnSelect property to:

Set(myLocation, BingMaps.GetLocationByPoint(Location.Latitude, Location.Longitude));
Set(myweather,MSNWeather.CurrentWeather(myLocation.address.addressLine,"Metric"))

2/add three label controls(Label1/ Label2/ Label3) and set their Text property to:

Label1:

"Area:"& myweather.responses.source.location

Label2:

"CAP:"& myweather.responses.weather.current.cap

Label3:

"Temp:"& myweather.responses.weather.current.temp&myLocation.units.temperature

Case2:do not use BingMap

1/add a button and set its OnSelect property to:

Set(myweather,MSNWeather.CurrentWeather(Location.Latitude&","&Location.Longitude,"Metric"))
 

Best Regards,

Bof

View solution in original post

Hi @v-bofeng-msft !

 

Thanks for your reply! I used a combination of the things mentioned by you and got the results I wanted. Here I'll share what I did for whoever is interested:

 

1. I set the OnStart property of the app to:

// LOCATION //

//Set some variables to retrieve current User's location

Set(myLocation, BingMaps.GetLocationByPoint(Location.Latitude, Location.Longitude));

//WEATHER

//Set variables to collect weather information
Set(myWeather,MSNWeather.CurrentWeather(Location.Latitude&","&Location.Longitude,"Metric"));
Set(myForecast,MSNWeather.TomorrowsForecast(Location.Latitude&","&Location.Longitude,"Metric"))

 

2. Created a Label for Location:

myLocation.address.formattedAddress

Note: I would like to only show the City here, but have not managed to do that yet

 

3. Created a label for Today's weather for my specific location:

myWeather.responses.weather.current.temp & " "& myWeather.units.temperature

 And one for tomorrow:

myForecast.responses.daily.tempLo & " "& myWeather.units.temperature & " - " & myForecast.responses.daily.tempHi & " "& myWeather.units.temperature

 

The result:
Annotation 2020-04-14 114638.png

 

Cheers,

Merel

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (54,747)