iandevlin.com

Icon

A mixture of musings on web design & development, history, and life

Marking an OS Grid Reference position on a Google Map

Cambridge Ordnance Survey Map

Last week I blogged over at PC Pro on how to display a location marker on a Google Map. This assumes that you either enter a standard address and/or postcode/zipcode and relies on Google’s Geocoder to perform the transformation from the entered details into a latitude and longitude value.

All good. But I received one comment on my PC Pro article asking about OS (Ordnance Survey) Grid References and displaying them on a Google Map.

Read the rest of this entry »

Javascript: checking what a string starts with

Just a quick and simple post, that’s possibly nothing new to you, but it might be useful to others.

If you want to perform a check on what a string starts with in Javascript, you can use the substring(startpos, endpos) method, startpos is a required parameter and indicates where in the string to start the extraction, endpos is optional and indicates where the extraction is to end (if not supplied, it will extract to the end of string).

For example, to check if a string starts with ‘ABC’ you would do the following:


var mystring = "ABCDEF";
var text =  mystring.substring(0, 3);
if (text == 'ABC') alert("string starts with ABC!');

Note that if the string being extracted from is shorter than the amount to extract, e.g. using the above example if mystring = 'AB', the extraction will still work, but in this case text = 'AB'.