Subs are not hidden when on coast tiles, only ocean tiles. If you were that close to the city, you were probably on the coast tiles, which revealed your sub. If you're going to position your subs for first-strike capabilities, keep them well away from enemy cities and ship patrol paths. Those nuclear missiles have a range of 8, so there's really no need to get any closer than that.
Something to keep in mind with bombs vs missiles: bombs damage all units in the blast radius, but missiles destroy all units in the blast radius (2 tile radius from impact point for both though). If you need to take out units around the city, use a missile.
Something to keep in mind with bombs vs missiles: bombs damage all units in the blast radius, but missiles destroy all units in the blast radius (2 tile radius from impact point for both though). If you need to take out units around the city, use a missile.