"The heart of the earth" is not a reference to the grave; it is a reference to the city of Jerusalem.
In the previous chapter we see Jesus calling out various cities where he performed mighty works, but they didn't repent of their wicked ways. And he compares them to other cities, making mention of these other cities being shown more tolerance at the day of judgment than those in which he performed these mighty works:
Then began he to upbraid the cities wherein most of his mighty works
were done, because they repented not:
Woe unto thee, Chorazin! woe
unto thee, Bethsaida! for if the mighty works, which were done in you,
had been done in Tyre and Sidon, they would have repented long ago in
sackcloth and ashes. But I say unto you, It shall be more tolerable
for Tyre and Sidon at the day of judgment, than for you.
And thou,
Capernaum, which art exalted unto heaven, shalt be brought down to
hell: for if the mighty works, which have been done in thee, had been
done in Sodom, it would have remained until this day. But I say unto
you, That it shall be more tolerable for the land of Sodom in the day
of judgment, than for thee. (Matthew 11:20-24 KJV)
Now, consider the immediate context:
Then certain of the scribes and of the Pharisees answered, saying,
Master, we would see a sign from thee. But he answered and said unto
them, An evil and adulterous generation seeketh after a sign; and
there shall no sign be given to it, but the sign of the prophet Jonas:
For as Jonas was three days and three nights in the whale's belly; so
shall the Son of man be three days and three nights in the heart of
the earth. (Matthew 12:38-40 KJV)
When those of the scribes & Pharisees asked to see a sign, Jesus said there would be no sign given to them, except for the sign of the prophet Jonah.
Many assume the sign he is speaking of is the fact that Jonah was in the belly of the whale, but if we keep reading, it becomes more clear that the sign is that the men of Nineveh repented at the preaching of Jonah.
The men of Nineveh shall rise in judgment with this
generation, and shall condemn it: because they repented at the
preaching of Jonas; and, behold, a greater than Jonas is here.
He contrasts "the men of Nineveh" with "this generation" saying those of Nineveh repented at the preaching of Jonah, yet while one who was greater than Jonah was in their midst, and they evidently were not repenting.
Now when Jesus refers to Jonah being three days and three nights in the belly of the whale, he contrasts that with his being three days and three nights in the heart of the earth.
The Greek word translated as "earth" is γῆ (G1093) and can also be translated as "land".
The Greek words translated as "belly" (G2836) and "heart" (G2588) are two different words referring to two different parts of the body. The former refers to "a cavity" in the middle of the body according to Thayer's Greek definitions; it is often translated as "womb" in the New Testament when speaking of women. The latter refers to "the heart", which is a vital body organ, through which all lifeblood flows; it is the life center.
Thayer's Greek Definitions says:
G2588
καρδία
kardia
Thayer Definition: 1) the heart 1a) that organ in
the animal body which is the centre of the circulation of the blood,
and hence was regarded as the seat of physical life 1b) denotes the
centre of all physical and spiritual life
According to Google's "define" feature, our English term "heartland" means "the central or most important part of a country, area, or field of activity." or "the center of support for a belief or movement."
While I don't typically refer to definitions of English words when I study the Bible, I cite this to demonstrate where we get that term from. The meanings of the two words that make up the English compound word supports what I am saying. The heart of the land there in Judea in Jesus' day was most certainly Jerusalem.
Given these meanings, another way of saying the latter part of verse 40 is: So shall the Son of Man be three days and three nights in the life center of the land or in the heartland.
Now, consider the verse that immediately follows:
The
queen of the south shall rise up in the judgment with this generation,
and shall condemn it: for she came from the uttermost parts of the
earth to hear the wisdom of Solomon; and, behold, a greater than
Solomon is here. (Matthew 12:42 KJV)
Notice there is a contrast being made between the heart of the land from verse 40 and the uttermost parts of the land in verse 42. When the queen of the south traveled to hear the wisdom of Solomon, notice where was he located:
And when the queen of Sheba heard of the fame of Solomon concerning
the name of the LORD, she came to prove him with hard questions. And
she came to Jerusalem with a very great train, with camels that bare
spices, and very much gold, and precious stones: and when she was come
to Solomon, she communed with him of all that was in her heart. And
Solomon told her all her questions: there was not any thing hid from
the king, which he told her not. (1 Kings 10:1-3 KJV)
So, the bottom line is that Matthew 12:40 is not addressing the time Jesus will spend in the grave. Rather, it is simply saying that he will spend three days and three nights in Jerusalem.
And the sign the scribes and Pharisees sought from Jesus was not given to them. Instead, Jesus referred to the sign of the prophet Jonah, that the men of Nineveh, having been steeped in wickedness, repented at the preaching of a coming destruction.
And we see later that Jerusalem did not repent at the preaching of Jesus.
EDITED 3/20/18:
There are about a dozen references in the New Testament of the Son of Man being killed and raised up on "the third day". The question is how is "the third day" counted in Scripture?
The first mention of the “third day” is found in Genesis 1 outlining the creation account.
We are told on day one, God said “Let there be light…”; on the second day, God said “Let there be an expanse in the midst of the waters…”; and on the third day, God said, "Let the waters under the heavens be gathered together…”. That would be one day, the second day, and the third day.
In another example where the third day is laid out for us is in Exodus 19 when the children of Israel came to Mt Sinai. We see three days: “today”, “tomorrow”, and then “the third day”.
And the LORD said to Moses, "Behold, I am coming to you in a thick
cloud, that the people may hear when I speak with you, and may also
believe you forever." When Moses told the words of the people to the
LORD, the LORD said to Moses, "Go to the people and consecrate them
today and tomorrow, and let them wash their garments and be ready for
the third day. For on the third day the LORD will come down on Mount
Sinai in the sight of all the people. (Exo 19:9-11)
In the New Testament we see Jesus counting the days in the same way: “to day”, “tomorrow”, and then “the third day”.
"The same day there came certain of the Pharisees, saying unto him,
Get thee out, and depart hence: for Herod will kill thee. And he said
unto them, Go ye, and tell that fox, Behold, I cast out devils, and I
do cures to day and to morrow, and the third day I shall be perfected.
Nevertheless I must walk to day, and to morrow, and the day following:
for it cannot be that a prophet perish out of Jerusalem." (Luke
13:31-33 KJV)
Given this, the third day would start with “today” (day 1), followed by tonight (night 1). Then there is “tomorrow” (day 2), followed by tomorrow night (night 2). Then there is “the third day” or “the day following” (day 3). That adds up to three days and two nights. This does not add up to three days and three nights.
Jesus was killed on one day, was buried and remained in the tomb that night, the next day and the next night, and then on the third day he was raised up.
There is only one reference in the New Testament of the Son of Man being in the heart of the land/earth for three days and three nights, and that is in Matthew 12:40, even though there are at least two other mentions in the New Testament to "the sign of Jonah". And with each of these mentions of the sign of Jonah, there is never any discussion of anyone being killed or raised up.
As far as where do we see Jesus spending three days and three nights in Jerusalem...
According to Matthew, it appears that the first of those three days in Jerusalem is when Jesus came into the city after spending the night in Bethany following his triumphal entry into Jerusalem and the clearing of the temple, and he cursed the fig tree (Mt. 21:18-20) and his stay spans the next 4 chapters.
In Matthew 26:2 he says, "Ye know that after two days is the passover, and the Son of man is betrayed to be crucified."
This was said at the end of DAY (1), then there'd be that NIGHT (1). Then, the next DAY (2) followed by the next NIGHT (2). And then "after two days" would be the Passover when he ate with his disciples, which would be DAY (3) followed by the next NIGHT (3) when the Son of Man was betrayed to be crucified.
That would be 3 days and 3 nights in heart of the land: Jerusalem.