cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

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 @Anonymous :

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

5 REPLIES 5
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.

 
Anonymous
Not applicable

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 @Anonymous :

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

Anonymous
Not applicable

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

Interestingly, If i use solution one, I am place in the wrong city.  If I use solution 2 it place mes in the right location

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (1,109)