function x0 = getlocation(M,sphere)
x0 = [0;0;6370;0.0001];
if sphere==1
    newM = ones(size(M));
    for i = 1:size(M,1)
        newM(i,1) = M(i,1)*cos(M(i,2))*cos(M(i,3));
        newM(i,2) = M(i,1)*cos(M(i,2))*sin(M(i,3));
        newM(i,3) = M(i,1)*cos(M(i,2));
        newM(i,4) = M(i,4);
    end
    M = newM;
end
if size(M,1)==4
    for n = 1:20
        x0 = x0 - (jacobian(M,x0))\(f(M,x0));
    end
elseif size(M,1)>4
    for n = 1:20
        j = jacobian(M,x0);
        x0 = x0 - j'*j\j'*f(M,x0);
    end
end