This is a multiple choice question:
Does a crime take place in the location of:
a) the perpetrator(s)
b) the victim(s)
c) somewhere else
d) all of the above.
The correct answer is d) all of the above.
Jurisdiction in criminal matters is decided by the courts of each jurisdiction. Let me expand one of your examples:
A US citizen resident in Canada hacks a server located in the UK to access the information of an Australian citizen resident in France but traveling in Germany and uses it to cause harm to the Australian's Mexican corporation's business in South Africa. Any or all of the courts of the US, Canada, the UK, Australia, France, Germany, Mexico and South Africa could hear the case.
Some may decide that they do not have jurisdiction because their connection is tenuous (e.g. Germany). Some may defer their jurisdiction to another jurisdiction - effectively saying "we have jurisdiction but will not hear the case; bring us the judgement from jurisdiction X and we will enforce it", this is very common. For example, if drug smuggling takes place between two countries the perpetrator will generally only be prosecuted where they are caught, however, if they are acquitted in the first jurisdiction they may have to face prosecution in the second.
The point is; jurisdiction is complicated.