Programming and Development

Posts filed under Programming and Dev

How to have multiple InfoWindows in Google Maps

This is part of a series of posts that I wanted to do around late October last year, I finally got to it.

When I was doing an assignment in Internet Programming last semester, we were given the task of using the Google Maps API. This assignment also required the use of custom markers, and to have Info Windows that are displayed upon clicking the multiple custom markers.

The Google Maps API example for InfoWindows was useful in displaying only one info window (a window with additional information if a marker is clicked), and this led me to thinking I could instantiate a new InfoWindow and add an event listener to it.

Something like this:

	//this is done inside a for-loop that goes through an array of data
	var infowindow = new google.maps.InfoWindow({
    content: contentString
  });
  	//marker is the marker object in the array
  	marker.addListener('click', function() {
    infowindow.open(map, marker);
  });
  	

However, this led to the InfoWindow only displaying information about the last item in the array of objects, no matter which marker I clicked.

After a bit of head scratching and Google-fu, I then realized I had stumbled onto an issue caused by closures.

Read more

How to Fade Out/In in JavaScript Properly

Recently for a project I had to implement fade in and fade out functions in JavaScript, without the use of JQuery. It’s amusing how much of the StackOverflow questions online focus on using JQuery, because it is admittedly easier to just call a library function.

Of course, I have seen implementations of fade in and fade out methods in pure JavaScript, such as this one, however, many of the articles I’ve found do not explain a means of fading out and then followed by fading in the next image. Admitted I’ve hit a very amateur snag in JavaScript programming, thinking that all functions are synchronous and execute after the previous instruction is complete.

Read more

Making Git Commits in the Past

Recently on a side project I’ve been working on I decided that I wanted to create a repository… 2 weeks later. This was because initially I felt I didn’t have much code to begin with, no point keeping a version control of code that hasn’t been written yet.. right?

By the time I decided to initialize a git for it, I decided I wanted to keep track of when I started, so I can have a gauge of the duration it took for me to develop the program, at least on whatever free off work hours I could find. Searching online didn’t lead me to the answers right away, so here’s how to create a commit back in time.

Read more

Behavior Change in String.split for Java 8

Recently on Stackoverflow a user posted a question regarding Java’s String.split() method, one that beginners are regularly exposed to in order to extract data within strings.

The user stumbled upon this when trying to test code in another machine, which happened to be running a different version of Java. Java 8 has changed the implementation of split() from having an empty string being added into the string array on first null element, to not adding an empty string into the array.

Read more