The past few days have been spent trying to attack the InfoWindow on my neighborhood map. I say "attack", as it has felt like a battle to get the last few features to work properly.
I have a series of locations for my map in geo-coordinates (latitude and longitude). I have decided to use Google's reverse geolocation API to turn those into addresses to display in the InfoWindow above a marker when it is clicked. However, doing the request causes an asynchronous function to fire (calling out to Google, and getting a response back) - and my code doesn't wait for the response. I can pull data, and verify it is coming back, but each request seems to show up well after the code has moved on.
I tried using setTimeout, but that didn't seem to allow any response at all to show up. I have moved the function in and out of several other functions, and even tried to run it on its own, but I keep getting an undefined display item in the window.
After more research, I decided to put the geocode request into the listener where I build the InfoWindow. This is working, thankfully, but I feel like it clutters the code a bit, and should be able to be refactored out on its own. Each time I try that, however, the process fails. So, for now, it will stay where it is.
This leaves me with one last major hurdle: implementing a third party API. I decided to look into using Flickr, as it seems to be pretty easy to pull photos based on the geolocation. I have found some basic instructions on how to pull pictures; getting them to display is going to be the more difficult part. Hopefully, it is not nearly as complicated as I am making it out to be.
I have a series of locations for my map in geo-coordinates (latitude and longitude). I have decided to use Google's reverse geolocation API to turn those into addresses to display in the InfoWindow above a marker when it is clicked. However, doing the request causes an asynchronous function to fire (calling out to Google, and getting a response back) - and my code doesn't wait for the response. I can pull data, and verify it is coming back, but each request seems to show up well after the code has moved on.
I tried using setTimeout, but that didn't seem to allow any response at all to show up. I have moved the function in and out of several other functions, and even tried to run it on its own, but I keep getting an undefined display item in the window.
After more research, I decided to put the geocode request into the listener where I build the InfoWindow. This is working, thankfully, but I feel like it clutters the code a bit, and should be able to be refactored out on its own. Each time I try that, however, the process fails. So, for now, it will stay where it is.
This leaves me with one last major hurdle: implementing a third party API. I decided to look into using Flickr, as it seems to be pretty easy to pull photos based on the geolocation. I have found some basic instructions on how to pull pictures; getting them to display is going to be the more difficult part. Hopefully, it is not nearly as complicated as I am making it out to be.
No comments:
Post a Comment